2010-10-26 16 views
5

Aşağıdaki gibi bir Model Rolü için bir EditorFor Şablonum var. Ayrıca EditörFor for Date'i doğrudan View from EditorFor'u kullandığımda, ancak editöre EditoFor'um olduğunda çalıştığım için iyi çalışmıyor. Herhangi bir fikir?MVC EditorFor İçinde Başka DüzenleyiciFor

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

Diğer şablonu da, tarih şablonunu ve modelin bir parçasını gönderebilir misiniz? –

cevap

0

Benim için çalışıyor.

Modeli:

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

Denetleyici:

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

View (~/Views/Home/Index.aspx): MyViewModel için

<%: Html.EditorForModel() %> 

Editör şablonu (~/Views/Home/EditorTemplates/MyViewModel.ascx):

DateTime

Editör şablonu (~/Views/Home/EditorTemplates/DateTime.ascx):

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DateTime>" %> 
<div>Some markup to edit date</div> 
1

Benim biri için çalışmaz; Bir çeşit anti-özyineleme koruması olduğunu düşünüyorum.

Dış çağrıyı 'EditorFor' yerine bir 'Kısmi' olarak değiştirirseniz, bunun yerine aynı .cshtml dosyasına işaret ederek - dahili 'EditorFor'lar çalışır.

İlgili konular