我的EditorFor
爲標題似乎通過DateTime
價值,而不是一個字符串,但我不明白我的生活爲什麼,當我註釋出的形式組問題它完美運行。EditorFor字符串,但它正在尋找DateTime
類別:
public class EventInputModel
{
[Required(ErrorMessage ="Event title is required.")]
[StringLength(200, ErrorMessage ="The {0} must be between {2} and {1{ characters long.", MinimumLength =1)]
[Display(Name ="Title")]
public string Title { get; set; }
[DisplayFormat(DataFormatString = "{0:t}")]
[DataType(DataType.DateTime)]
[DateVal(ErrorMessage = "Incorrect DateTime")]
[Display(Name ="Date and Time *")]
public DateTime StartDateTime { get; set; }
public TimeSpan? Duration { get; set; }
public string Description { get; set; }
[MaxLength(200)]
public string Location { get; set; }
[Display(Name ="Is Public?")]
public bool IsPublic { get; set; }
}
@{
ViewBag.Title = "Create New Event";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Create</title>
</head>
<body>
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>EventInputModel</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
</div>
</div>
錯字:'必須在{2}和{1 {'之間。可能有關係,可能不會。 – markpsmith
EditorFor在哪裏?這也可能是錯誤所在。 –
@markpsmith感謝您發現,典型的情況是daft –