Suppose we have some kind of action in the controller:
public ActionResult SomeAction()
{
return View();
}
I want to be able to add some HTML code at the end of the presentation of the HTML result using attributes, for example:
[SomeHTML]
public ActionResult SomeAction()
{
return View();
}
Where
public class SomeHTMLAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
var response = filterContext.HttpContext.Response;
if (response.ContentType == "text/html")
{
response.Write("someHTML");
}
}
}
Filters (ActionFilterAttribute) allow you to add HTML code to the top or bottom of a web page, but not to the end of the HTML view.
How to do it?
source
share