MVC HtmlHelper 扩展

定义,

 1 namespace System.Web.Mvc
 2 
 3 {
 4 
 5   public static class myTab
 6 
 7   {
 8 
 9     public static MvcHtmlString beginJs(this HtmlHelper helper)
10 
11     {
12 
13       return new MvcHtmlString("<script>function xxtest(obj){obj.style.display='none';}</script>");
14 
15     }
16 
17     public static MvcHtmlString tableXX(this HtmlHelper helper)
18 
19     {
20 
21       TagBuilder tb = new TagBuilder("input");
22 
23       tb.MergeAttribute("type", "button");
24 
25       tb.MergeAttribute("value", "click me");
26 
27       tb.MergeAttribute("onclick","xxtest(xx1)");
28 
29       tb.MergeAttribute("style","background-color:red");
30 
31       return new MvcHtmlString(tb.ToString(TagRenderMode.Nomal));
32 
33     }
34 
35   }
36 
37 }

调用,

@Html.beingJs()

@Html.tableXX()

作者:zc
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/jmzs/p/3652281.html