我几乎尝试了我在互联网上阅读的所有内容,在这个网站上(web.config 中的全球化文化,在我的模型中添加的 DisplayFormat,......)但我没有找到我的答案。
我的网络应用程序允许用户通过提供一些信息来创建人员。这些信息之一是开始日期,它是一个 DateTime 值。我正在使用 jQuery UI 日期选择器来允许通过日历选择日期。当我选择我的日期(实际上是一天大于 12 的日期)时,应用程序会向我显示一条验证错误消息。例如,如果我选择今天的日期,则会出现:值 '03/15/2013' 对于 StartDate 无效。
我的观点 :
@model BuSIMaterial.Models.Person
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Person</legend>
<div class="editor-label">
First name :
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.FirstName, new { maxlength = 50 })
@Html.ValidationMessageFor(model => model.FirstName)
</div>
<div class="editor-label">
Last name :
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.LastName, new { maxlength = 50 })
@Html.ValidationMessageFor(model => model.LastName)
</div>
<div class="editor-label">
National number :
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.NumNat, new { maxlength = 11 })
@Html.ValidationMessageFor(model => model.NumNat)
</div>
<div class="editor-label">
Start date :
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.StartDate, new {@class = "datepicker" })
@Html.ValidationMessageFor(model => model.StartDate)
</div>
<div class="editor-label">
End date :
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.EndDate, new { @class = "datepicker" })
@Html.ValidationMessageFor(model => model.EndDate)
</div>
<div class="editor-label">
Distance House - Work (km) :
</div>
<div class="editor-field">
@Html.EditorFor(model => model.HouseToWorkKilometers)
@Html.ValidationMessageFor(model => model.HouseToWorkKilometers)
</div>
<div class="editor-label">
Category :
</div>
<div class="editor-field">
@Html.DropDownList("Id_ProductPackageCategory", "Choose one ...")
@Html.ValidationMessageFor(model => model.Id_ProductPackageCategory) <a href = "../ProductPackageCategory/Create">Add a new category?</a>
</div>
<div class="editor-label">
Upgrade? :
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Upgrade)
@Html.ValidationMessageFor(model => model.Upgrade)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/jqueryui")
@Styles.Render("~/Content/themes/base/css")
<script type="text/javascript">
$(document).ready(function () {
$(".datepicker").datepicker({
});
});
</script>
}
我的人模型中的开始日期:
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.DateTime StartDate
{
get
{
return _StartDate;
}
set
{
OnStartDateChanging(value);
ReportPropertyChanging("StartDate");
_StartDate = StructuralObject.SetValidValue(value);
ReportPropertyChanged("StartDate");
OnStartDateChanged();
}
}
private global::System.DateTime _StartDate;
partial void OnStartDateChanging(global::System.DateTime value);
partial void OnStartDateChanged();
有没有人有解决这个问题的方法?