开发者

MS MVC3 Nested EditorFor and View Templates with same ViewModel

开发者 https://www.devze.com 2023-03-22 03:06 出处:网络
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 hav

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

精彩评论

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