Asp.net mvc 从Jquery datepicker到MVC问题的日期时间绑定
我们使用jQueryUIDatePicker 当我以以下格式输入日期时:2012年9月22日asp.net MVC表示该日期的格式无效 当我查看通过绑定填充的viewmodel时,它表示日期字段:Asp.net mvc 从Jquery datepicker到MVC问题的日期时间绑定,asp.net-mvc,asp.net-mvc-3,jquery-ui,jquery-ui-datepicker,Asp.net Mvc,Asp.net Mvc 3,Jquery Ui,Jquery Ui Datepicker,我们使用jQueryUIDatePicker 当我以以下格式输入日期时:2012年9月22日asp.net MVC表示该日期的格式无效 当我查看通过绑定填充的viewmodel时,它表示日期字段:NULL 当我查看请求时,我将其视为发布值:9%2f22%2f2012 在受保护的覆盖void OnActionExecuting(ActionExecutingContext filterContext))中,我设置了如下区域性 CultureInfo culture = ne
NULL
当我查看请求时,我将其视为发布值:9%2f22%2f2012
在受保护的覆盖void OnActionExecuting(ActionExecutingContext filterContext))
中,我设置了如下区域性
CultureInfo culture = new CultureInfo(language.LanguageISO);
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
其中,language.LanguageISO
在本例中是“en
”
我以为模型装订工会接受这种文化
日期中的斜杠转义为
%2f
,这可能是一个问题吗?请尝试像这样配置日期选择器
$('.has_datepicker').datepicker({
dateFormat: '@System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.Replace("M", "m").Replace("yy", "y")'
在
OnActionExecuting
事件中设置区域性已经太晚了。模型绑定器已在此阶段运行。您需要在运行模型绑定器之前更早地设置它。例如,您可以实现IAuthorizationFilter
接口:
public class SomeCustomAttribute : ActionFilterAttribute, IAuthorizationFilter
{
public void OnAuthorization(AuthorizationContext filterContext)
{
// TODO: set the culture here so that it's picked up by the model binder
CultureInfo culture = new CultureInfo(language.LanguageISO);
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
}
}
按照以下步骤操作:
1. @Html.TextBox(“date”,Model.ToString(“dd/MM/yyyy”),新的{@class=“date”})
2.
///
///
$(文档).ready(函数(){
$('.date').datepicker({dateFormat:“dd/mm/yy”});
});
嘿,达林,你吓到我了,你知道的太多了,这确实起到了作用!
Follow the step:
1. @Html.TextBox("date", Model.ToString("dd/MM/yyyy"), new { @class = "date" })
2.
/// <reference path="jquery-1.4.4.js" />
/// <reference path="jquery-ui.js" />
$(document).ready(function () {
$('.date').datepicker({dateFormat: "dd/mm/yy"});
});