MVC EditorFor 位于另一个 EditorFor 内
我有一个模型角色的 EditorFor 模板,如下所示。我还有 EditorFor for Date,当我直接从 View 使用 EditorFor 时,它工作正常,但当我在编辑器内使用 EditoFor 时,它不起作用。有什么想法吗?
Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl[ucsrManagementSystem.Models.ContactsInMailingListsViewModel]"
Html.EditorFor(m => m.IsInMainlingList)
Html.EditorFor(m => m.Id)
Html.EditorFor(m => m.Name)
Html.EditorFor(m => m.EndDate)//This is not showing Date's Editor Template when inside another EditorFor
I have an EditorFor Template for a Model Role as below. I also have EditorFor for Date which works fine when I use EditorFor directly from View but when I have EditoFor inside an editor for it doesn't work. Any idea?
Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl[ucsrManagementSystem.Models.ContactsInMailingListsViewModel]"
Html.EditorFor(m => m.IsInMainlingList)
Html.EditorFor(m => m.Id)
Html.EditorFor(m => m.Name)
Html.EditorFor(m => m.EndDate)//This is not showing Date's Editor Template when inside another EditorFor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我有用。
模型:
控制器:
视图 (
~/Views/Home/Index.aspx
):MyViewModel 的编辑器模板 (
~/Views/Home/EditorTemplates/MyViewModel.ascx
):编辑器日期时间模板 (
~/Views/Home/EditorTemplates/DateTime.ascx
):It works for me.
Model:
Controller:
View (
~/Views/Home/Index.aspx
):Editor template for MyViewModel (
~/Views/Home/EditorTemplates/MyViewModel.ascx
):Editor template for DateTime (
~/Views/Home/EditorTemplates/DateTime.ascx
):对我来说也不起作用;我认为这是某种反递归保护。
如果将对“EditorFor”的外部调用更改为“Partial” - 即使指向同一个 .cshtml 文件 - 内部的“EditorFor”也将起作用。
It doesn't work for me either; I'm presuming that it's some kind of anti-recursion protection.
If you change the outer call to 'EditorFor' to a 'Partial' instead - even pointing at the same .cshtml file - the inner 'EditorFor's will work.