public static mvchtmlstring Inputtextfor<tmodel, tvalue> (this htmlhelper<tmodel> HTML, Expression<func <tmodel, tvalue>> expression,object attr=null)
{
DisplayAttribute disp = null;
Vilidateattribute vilidate = null;
String name = String. Empty;
Try
{
Dynamic exp = expression. Body.gettype (). GetProperty ("Member"). GetValue (expression. Body, NULL);
var strName = (String) exp. Name;
var p = typeof (TModel). GetProperty (StrName);
DISP = P.getcustomattributes (typeof (DisplayAttribute), false). FirstOrDefault () as DisplayAttribute;
Vilidate = P.getcustomattributes (typeof (Vilidateattribute), false). FirstOrDefault () as Vilidateattribute;
name = StrName;
}
catch (Exception e)
{
}
Tagbuilder tag = new Tagbuilder ("input");
Tag. Mergeattribute ("type", "text");
Tag. Mergeattribute ("Class", "Form-control");
Tag. Mergeattribute ("id", "I" + name);
Tag. Mergeattribute ("name", "n" + name);
Tag. Mergeattribute ("placeholder", "Please enter" + disp. Name);
Verify
foreach (var item in Vilidate. GetInfo ())
{
Tag. Mergeattribute (item. Key, item. Value);
}
Additional
if (attr!=null)
{
foreach (var item in attr. GetType (). GetProperties (Reflection.BindingFlags.Instance | Reflection.BindingFlags.Public))
{
Tag. Mergeattribute (item. Name, item. GetValue (attr, NULL). ToString ());
}
}
Tag. InnerHtml = DISP = = null? "Display not Set": "";
return new mvchtmlstring (tag. ToString ());
}
MVC htmlhelp class extension for lambda expression mode