asp.net MVC中的自定义标签

时间:2011-01-21 06:47:29

标签: asp.net-mvc tags

我是MVC的新手,我想知道如何在asp.net MVC中创建自定义标签?

1 个答案:

答案 0 :(得分:0)

也许是这样的:

    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)