c# - Retrieve [Display] Attribute Name in HTML Helper -


we have custom html helper following signature.

public static mvchtmlstring textboxfor<tmodel,     tproperty>(this htmlhelper<tmodel> helper,     expression<func<tmodel, tproperty>> property) {     var htmlattributes = new dictionary<string, object>();      // ....      return helper.textboxfor(property, htmlattributes); } 

i implement placeholder attribute here, should set label control. label can either string constant or string specified property's [display] attribute.

is there way me label helper function?

this seems work:

modelmetadata metadata = modelmetadata.fromlambdaexpression(property, helper.viewdata); string htmlfieldname = expressionhelper.getexpressiontext(property); string labeltext = metadata.displayname ?? metadata.propertyname ?? htmlfieldname.split('.').last(); if (!string.isnullorwhitespace(labeltext))     // labeltext contains label 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -