我有一个模型角色的EditorFor模板,如下所示。我也有EditorFor for Date,当我在视图中直接使用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发布于 2015-07-16 18:00:28
它对我也不起作用;我假设它是某种反递归保护。
如果你将外部调用'EditorFor‘改为'Partial’--甚至指向相同的.cshtml文件--内部的‘EditorFor’将会起作用。
发布于 2010-10-27 14:36:42
这对我很管用。
型号:
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>https://stackoverflow.com/questions/4026784
复制相似问题