MS MVC3 嵌套 EditorFor 和具有相同 ViewModel 的视图模板
我有一个需要渲染编辑器的模型层次结构。
我想要一个漂亮的 ViewModel,其中包含层次结构每个部分渲染自身所需的所有信息,并让该 ViewModel 沿着模板链传递。
我已将 View 强类型化到该 ViewModel,并且可以很好地进入第一级嵌套:
MyView.cshtml:
@model MyViewModel
@Html.EditorFor(x => x, "ViewTemplateA", "ViewTemplateA")
Within EditorTemplates/ViewTemplateA.cshtml:
@model MyViewModel
@Html.EditorFor(x => x, "ViewTemplateB", "ViewTemplateB")
--- 到这里为止都正常,ViewTemplateA 被渲染 --
EditorTemplates/ViewTemplateB。 cshtml:
@model MyViewModel
...etc...
-- ViewTemplateB 永远不会被调用。如果我将其 @model
更改为其他内容,并传入不同的对象进行匹配,例如 x =>; x.SubModel
,它被调用。
有什么想法吗?
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??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论