C# EditorTemplate未在我的视图中覆盖我的文本框
我无法让我的DateTime EditorTemplate工作 我的ViewModel中有:C# EditorTemplate未在我的视图中覆盖我的文本框,c#,asp.net-mvc,asp.net-mvc-3,razor,C#,Asp.net Mvc,Asp.net Mvc 3,Razor,我无法让我的DateTime EditorTemplate工作 我的ViewModel中有: public class CreateViewModel { // Customer public int CustomerId { get; set; } [Required] [DataType(DataType.DateTime)] [Display(Name = "Arrival Date")] [DisplayFormat(DataFormat
public class CreateViewModel
{
// Customer
public int CustomerId { get; set; }
[Required]
[DataType(DataType.DateTime)]
[Display(Name = "Arrival Date")]
[DisplayFormat(DataFormatString = "{0:dd MMM yyyy}", ApplyFormatInEditMode = true)]
[UIHint("DateTime")]
public DateTime ArrivalDate { get; set; }
}
我的Shared->EditorTemplates文件夹中还有DateTime.cshtml:
@model DateTime?
@Html.TextBox(
"",
string.Format("{0:dd MMM yyyy}", Model ?? DateTime.Today),
new {
@class = "textbox datepicker"
}
)
我认为:
@Html.TextBoxFor(m => m.ArrivalDate)
但是,my DateTime.cshtml似乎没有被调用,因为它仍然在文本框中显示日期,如下所示:
2013年7月15日00:00:00
但应该是2013年7月15日——没有时间
我错过了什么
谢谢。如果您想使用和编辑模板,您需要使用
Html.Editor
或Html.EditorFor
如果使用任何其他帮助程序,如Html.TextBox
或Html.TextboxFor
,则不会应用该模板
类似地,如果要使用显示模板,则需要使用
Html.Display
或Html.DisplayFor
如果要使用和编辑模板,则需要使用Html.Editor
或Html.EditorFor
如果使用任何其他帮助程序,如Html.TextBox
或Html.TextboxFor
,则不会应用该模板
类似地,如果你想使用显示模板,你需要使用
Html.Display
或Html.DisplayFor
你是使用Html.TextBox还是Html.Display?嗨-我在使用:@Html.TextBoxFor(m=>m.ArrivalDate)啊哈-我现在明白了,如果你使用EditorFor它工作!!!请把这个标记为正确答案。这可以帮助其他人。你使用的是Html.TextBox还是Html.Display?嗨-我使用的是:@Html.TextBoxFor(m=>m.ArrivalDate)啊哈-我现在明白了,如果你使用的是EditorFor它可以工作!!!请把这个标记为正确答案。这可以帮助其他人。