开发者

MS MVC3 Nested EditorFor and View Templates with same ViewModel

I have a hierarchy of开发者_运维技巧 Models I need to render out editors for.

I want to have a nice ViewModel that contains all the info needed for each part of the hierarchy to render itself and have that ViewModel get passed down the chain of templates.

I have strongly typed View to that ViewModel, and I can get to the first level of nesting fine:

MyView.cshtml:

@model MyViewModel

@Html.EditorFor(x => x, "ViewTemplateA", "ViewTemplateA")

Within EditorTemplates/ViewTemplateA.cshtml:

@model MyViewModel

@Html.EditorFor(x => x, "ViewTemplateB", "ViewTemplateB")

---works OK up to here, ViewTemplateA gets rendered--

EditorTemplates/ViewTemplateB.cshtml:

@model MyViewModel
...etc...

-- ViewTemplateB never gets called. If I change it's @model to something else, and pass in a different object to match, such as x => x.SubModel, it gets called.

Any ideas??

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜