Jquery MVC 5客户端验证文化
我将Jquery MVC 5客户端验证文化,jquery,asp.net-mvc,validation,culture,globalize,Jquery,Asp.net Mvc,Validation,Culture,Globalize,我将Web.config文件中的区域性更改为es CL,服务器端验证工作正常,但当我尝试提交数据时,客户端验证会在2016年11月25日等日期出现错误,因为它仍然使用英语日期格式,如2016年11月25日 我发现这篇文章差不多,但日期改为小数: 问题是所有的答案都过时了,因为更新的全球化插件不再使用全球化文件,比如globalize.culture.es-CL.js在包中不存在。(或者我遗漏了什么?) 如何将客户端验证区域性设置为es CL或es MX 以下是我的查看代码: &l
Web.config
文件中的区域性更改为es CL,服务器端验证工作正常,但当我尝试提交数据时,客户端验证会在2016年11月25日等日期出现错误,因为它仍然使用英语日期格式,如2016年11月25日
我发现这篇文章差不多,但日期改为小数:
问题是所有的答案都过时了,因为更新的全球化插件不再使用全球化文件,比如globalize.culture.es-CL.js
在包中不存在。(或者我遗漏了什么?)
如何将客户端验证区域性设置为es CL或es MX
以下是我的查看代码:
<div class="form-group">
@Html.LabelFor(model => model.ReleaseDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@* i set the @type = "text" because i will use a Jquery DatePicker instead the browser's DatePicker, and the @class = datepicker adds the DatePicker. *@
@Html.EditorFor(model => model.ReleaseDate, new { htmlAttributes = new { @class = "form-control datepicker", @type = "text" } })
@Html.ValidationMessageFor(model => model.ReleaseDate, "", new { @class = "text-danger" })
</div>
</div>
控制器操作:
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Movie movie = db.Movies.Find(id);
if (movie == null)
{
return HttpNotFound();
}
return View(movie);
}
谢谢。使用
@Html.EditorFor()
然后使用新建{type=“text”}
没有任何意义,它应该是@Html.TextBoxFor(m=>m.ReleaseDate,new{@class=“form control datepicker”})
。和[DataType(DataType.Date)]
以及[DisplayFormat]
的ApplyFormatInEditMode=true
属性只有在使用EditorFor()
时才受尊重,而不重写type
属性,因此这两个属性都应该被删除。您需要重写$.validator
(根据MM/dd/yyyy
格式验证日期)。您的class=“datepicker”
建议您可能正在使用jquery插件,因此请参考jquery ui datepicker,或者您是否找到了解决方案?我面临着完全相同的问题…使用@Html.EditorFor()
然后新建{type=“text”}
没有任何意义,它应该只是@Html.TextBoxFor(m=>m.ReleaseDate,new{@class=“form control datepicker”}
)和[DataType(DataType.Date)]
以及[DisplayFormat]
的ApplyFormatInEditMode=true
属性,只有在使用EditorFor()时才受尊重
而不重写类型
属性,因此这两个属性都应该被删除。您需要重写$.validator
(它基于MM/dd/yyyy
格式验证日期)。您的class=“datepicker”
建议您可能正在使用jquery插件,请参考jquery ui日期选择器,或者您找到解决方案了吗?我面临着完全相同的问题。。。
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Movie movie = db.Movies.Find(id);
if (movie == null)
{
return HttpNotFound();
}
return View(movie);
}