[英]custom tags in asp.net MVC
我是MVC的新手,我想知道如何在asp.net MVC中创建自定义标签?
也许是这样的:
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());
}
}
并且比内部视图更像这样使用它:
@Html.MyTag("custom", "Text", attributes)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.