c# - How to retrieve Display attribute in the Html Helper (GroupName) -
in htmlhelper i'm trying retrieve displayattribute.groupname of property, using
modelmetadata.fromlambdaexpression(expression, html.viewdata)
however, property "groupname" missing in modelmetadata.
i googled solutions , saw quite complex manipulations, while hope can solved easier.
any suggestions appreciated!
i have example may work. use create custom helper. hope works you:
public static mvchtmlstring datepickerfor<tmodel, tproperty>(this htmlhelper<tmodel> htmlhelper, expression<func<tmodel, tproperty>> expression, string classname) { if (expression == null) { throw new argumentnullexception("expression"); } var expressiontext = expressionhelper.getexpressiontext(expression); var metadata = modelmetadata.fromlambdaexpression(expression, htmlhelper.viewdata); var me = (expression.body memberexpression); var display = me .member .getcustomattributes(typeof(displayattribute), false) .cast<displayattribute>() .firstordefault(); string paramdisplayname = display.name; //this need return new mvchtmlstring(datepicker(htmlhelper, expressiontext, classname, htmlhelper.viewdata.eval(expressiontext), validations)); }
and how call method:
@html.datepickerfor(model => model.selectedmilestone.deliverydate, "core2-form-textbox-date")