views:

21

answers:

1

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
A: 

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>
Darin Dimitrov