今天公司要写学习总结,想着想着还是先写一篇关于MVC内部什么东东的博客整理整理再发表吧,一举两得。
之前写过了路由、过滤器等。今天就研究一下怎么自定义MVC控件吧。
本人技术小菜,不喜勿喷。。。。。(说这句话通常有两种情况,一种是牛人谦虚的说法,一种是怕受伤害提前准备个挡箭牌)
首先我们先去熟知一下MVC内部的那些控件是怎么实现的。
首先,Input标签是大佬,我给各位看管来上一小段Password的吧。
1 2 public static class InputExtensions { 3 public static MvcHtmlString Password(this HtmlHelper htmlHelper, string name) { 4 return Password(htmlHelper, name, null /* value */); 5 } 6 7 public static MvcHtmlString Password(this HtmlHelper htmlHelper, string name, object value) { 8 return Password(htmlHelper, name, value, null /* htmlAttributes */); 9 } 10 11 public static MvcHtmlString Password(this HtmlHelper htmlHelper, string name, object value, object htmlAttributes) { 12 return Password(htmlHelper, name, value, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); 13 } 14 15 public static MvcHtmlString Password(this HtmlHelper htmlHelper, string name, object value, IDictionary<string, object> htmlAttributes) { 16 return PasswordHelper(htmlHelper, null /* metadata */, name, value, htmlAttributes); 17 } 18 19 [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")] 20 public static MvcHtmlString PasswordFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression) { 21 return PasswordFor(htmlHelper, expression, null /* htmlAttributes */); 22 } 23 }