c# - How do you access the model in an EditorFor template? -
how access model in asp.net mvc editor template? example if parent view contains say:
@html.editorfor(x => x.surname)
then inside views/shared/editortemplates/string.cshtml have:
@model string <div class="field"> @html.labelfor(x => x) @html.textboxfor(x => x) @model.length </div>
this fails @ @model.length
because model
null, although labelfor
, textboxfor
render correct surname properties.
when html.displayfor
equivalent template file used, model
contain given string value.
creating editor template broad string
have unintended consequences, since have many editorfor(x => x.stringvalue)
s in code don't want editor template apply to.
it's have editorfor
causing nullref exception here.
Comments
Post a Comment