asp.net mvc 3 - mvc3 labelfor subobject -


i have 2 classes :

public class foo{     [display(name="here bar")]     public bar mybar;      [display(name="here name")]     public string myname;  }  public class bar{     ... } 

i have view "choosebar.cshtml" typed of foo.

if put @html.labelfor(model => model.myname) -> see "here name" in label. but, if put @html.labelfor(model => model.mybar) -> see "mybar", not expected "here bar"

how can use labelfor subobject ?(i.e displaying "here bar" instead of "mybar" in label)

thanks answer.

you decorate bar's property want render attribute:

public class bar {    [display(name="here bar")]    public string barname { get; set; } } 

and use custom editor template:

bar.cshtml

@html.labelfor(model => model.barname) 

choosebar.cshtml

@html.editorfor(model => model.bar) 

could way, use editor/display templates when want render sub-model.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -