2011-02-10 71 views
0

我目前正在覆蓋EditorFor一個自定義的幫手,如果DateTime對象有一個最小值集合,它顯示一個DateTime對象作爲一個空字符串。爲此,它使用TextBoxFor幫手:覆蓋ASP MVC EditorFor模板幷包含原始的EditorFor參數?

<%: Html.TextBox("", (Model != DateTime.MinValue ? Model.Date.ToString("ddMMMyy") : string.Empty), new { @class = "edit-date-field" })%> 

的問題是,當我用這個像這樣:

<%: Html.EditorFor(m => m.StartDate, new { id = "field-id", @class = "field-class"})%> 

我預計MVC保留現場-id和現場級的屬性,而是在生成的元素具有id =「StartDate」,並且只有一個類,class =「edit-date-field」。

那麼,如何保留原始調用EditorFor中包含的屬性?如果我將原始ID和類屬性添加到模板中,那麼與使用DateTime對象對EditorFor的所有調用將獲得不同於我想要的特定元素/值對。

謝謝!

回答

0

讓我澄清一下,你要使用文本框更換EditorFor

你原來文本框的HTML幫助不具備ID集和類屬性設置爲編輯日期字段

試試這個:

<%: Html.TextBox("field-id", (Model != DateTime.MinValue ? Model.Date.ToString("ddMMMyy") : string.Empty), new { @class = "field-class" })%>