2011-01-21 77 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)