开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜