5

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
4

2 回答 2

1

它对我也不起作用;我假设这是某种反递归保护。

如果您将对“EditorFor”的外部调用改为“Partial”——即使指向同一个 .cshtml 文件——内部的“EditorFor”也会起作用。

于 2015-07-16T10:00:28.197 回答
0

It works for me.

Model:

public class MyViewModel
{
    public DateTime Date { get; set; }
}

Controller:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View(new MyViewModel
        {
            Date = DateTime.Now
        });
    }
}

View (~/Views/Home/Index.aspx):

<%: Html.EditorForModel() %>

Editor template for MyViewModel (~/Views/Home/EditorTemplates/MyViewModel.ascx):

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyApp.Models.MyViewModel>" %>
<%: Html.EditorFor(x => x.Date) %>

Editor template for DateTime (~/Views/Home/EditorTemplates/DateTime.ascx):

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime>" %>
<div>Some markup to edit date</div>
于 2010-10-27T06:36:42.080 回答