...
To activate this subsystem, set up the FilterConfig.cs file like this:
Code Block | ||
---|---|---|
| ||
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
|
...
... |
...
filters.Add(new ProcessIncludesAttribute()); |
...
filters.Add(new ProcessHtmlAttribute()); } |
If you prefer, you can use these filter attributes like any other in MVC and apply them locally instead of globally.
...
The functionality is accessed through some custom extensions to the HtmlHelper listed below:
Code Block | ||
---|---|---|
| ||
@Html.RegisterScript(string script)
@Html.RegisterScript(string id, string script, List<string> dependencies)
@Html.RegisterCss(string url) @Html.RegisterLocalStyles(string id, string style)
@Html.RegisterHtmlBlock(string id, string html)
@Html.RegisterHtmlBlock(string id, MvcHtmlString html)
@Html.ScriptIsRegistered(string id)
@Html.CssIsRegistered(string id)
@Html.LocalStyleIsRegistered(string id)
@Html.HtmlBlockIsRegistered(string id) |
The RegisterScript functions add a script into the page once. If the 'script' argument starts with the string "javascript:" the script after this is taken to be Javascript to be inserted inline. If not, it is assumed to be the url for a script file.
...