Haven't written a blog for a long time, recently only read blog not write habits very bad ah.
Well, most recent projects have used a lot of forms, many forms have special writing, but there are a lot of duplication in the project, this time if can be encapsulated into htmlhelper will greatly reduce the workload.
Here's a basic usage model, Memo
Using system;using system.collections.generic;using system.linq;using system.linq.expressions;using System.Web; After the using system.web.mvc;//introduces the following namespaces, it is possible to come out of the view directly @ namespace system.web.mvc{public static class Formhtmlhelper { Private Const string editorwidth = "100"; Private Const string editorheight = "100"; Give the following method the first argument to this HtmlHelper helper, so you can @ht in//points out, otherwise you have to @[the custom class]. [Your method]. The following method seems to need to pass in two values,//actually as long as the @html. You can order it out. public static mvchtmlstring Necessarylabeler (this htmlhelper helper,st Ring name) {var ntag = new Tagbuilder ("span"); Ntag. addCssClass ("Red"); Ntag. Setinnertext ("*"); var nametag = new Tagbuilder ("span"); Tag. addCssClass (""); NameTag. Setinnertext (name); return new Mvchtmlstring (Ntag. ToString () +nametag. ToString ()); }//The following method can pass the model of the view in, get the value of the method to see the following LAMDA expression ... public static mvchtmlstring Disablededitorfor<tmodel, TValue> (this htmlhelper<tmodel> html, Expression<func<tmodel, tvalue>> Expression) {Obje CT data = Modelmetadata.fromlambdaexpression<tmodel, tvalue> (expression, HTML. ViewData). Model; if (data = = null) {data= ""; }//to do want! } }}