c# - Access complex data properties using HtmlHelper -


i coding extension helper similar displayfor in mvc advantage of mine retrieve actual property name resources file.

public class gender     {        public int id{get;set;}        public string name{get; set;}        public string arabicname{get;set;}     }  public class employee {     public int id{get;set;}     public string name{get;set;}     public string arabicname{get;set;}     public gender gender{get;set;} }  public static mvchtmlstring displayresourcefor<tmodel, tvalue>(this htmlhelper<tmodel> helper,             expression<func<tmodel, tvalue>> expression)         {             var rm = new resourcemanager("resources.global",                 system.reflection.assembly.load("app_globalresources"));                             var property = expressionhelper.getexpressiontext(expression);             string resourcename = string.empty;             var split = property.split('.');             property = string.empty;             // rebuild expression taking last name resource file             (var index = 0; index < split.length; index++)             {                 if (index == split.length - 1) // retrieve data rm                     property += (string.isnullorwhitespace(property) ? "" : ".") + rm.getstring(string.format("{0}resource", split[index]));                 else                     property += (string.isnullorwhitespace(property) ? "" : ".") + split[index];             }             var value = helper.viewcontext.viewdata.getviewdatainfo(property);              return value == null ? mvchtmlstring.empty : mvchtmlstring.create(value.value.tostring());          } 

the above code not work complex data like

@html.displayresourcefor(model =>model.gender.name) 

i tried use modelmetadata.fromstringexpression(property,helper.viewdata) returned values empty

what missing part in code?

any highly appreciated


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -