开发者

custom tags in asp.net MVC

开发者 https://www.devze.com 2023-02-06 02:59 出处:网络
I am n开发者_运维知识库ew to MVC and i want to know how to create custom tags in asp.net MVC?Maybe something like this:

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

精彩评论

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