custom tags in asp.net MVC
I am n开发者_运维知识库ew to MVC and i want to know how to create custom tags in asp.net MVC?
Maybe something like this:
public static class HtmlExtensions
{
public static MvcHtmlString MyTag(this HtmlHelper helper, string tagName, string innerText, Dictionary<string, string> attributes)
{
TagBuilder tag = new TagBuilder(tagName);
tag.SetInnerText(innerText);
tag.MergeAttributes<string, string>(attributes);
return MvcHtmlString.Create(tag.ToString());
}
}
and than inside view use it like this:
@Html.MyTag("custom", "Text", attributes)
精彩评论