2011-01-21 80 views
0

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

+3

你是什么意思自定义标签?在``或`Html.MyControl(...)`中? – 2011-01-21 06:50:05

回答

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)