我有一个模型角色的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
答案 0 :(得分:1)
它对我也不起作用;我认为它是某种反递归保护。
如果你将外部调用'EditorFor'更改为'Partial'而不是 - 甚至指向相同的.cshtml文件 - 内部'EditorFor'将起作用。
答案 1 :(得分:0)
它对我有用。
型号:
public class MyViewModel
{
public DateTime Date { get; set; }
}
控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new MyViewModel
{
Date = DateTime.Now
});
}
}
查看(~/Views/Home/Index.aspx
):
<%: Html.EditorForModel() %>
MyViewModel的编辑器模板(~/Views/Home/EditorTemplates/MyViewModel.ascx
):
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyApp.Models.MyViewModel>" %>
<%: Html.EditorFor(x => x.Date) %>
DateTime的编辑器模板(~/Views/Home/EditorTemplates/DateTime.ascx
):
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime>" %>
<div>Some markup to edit date</div>