私は「ES-MX」文化とasp.net MVCアプリケーションを持っています。ここで私は私のweb.configファイルで持っているものです。剣道日付ピッカーグローバリゼーションバインディング問題
@(Html.Kendo().DatePickerFor(model => model.StartDate)
.HtmlAttributes(new { @class = "input-field" })
)
:私はこのような剣道日付ピッカーを持って
<script type="text/javascript">
$(function() {
//set current to the "es-MX" culture script
kendo.culture("es-MX");
})
</script>
:
<globalization enableClientBasedCulture="true" uiCulture="es-MX" culture="es-MX"></globalization>
そして、ここで私は私の_layoutページに持っているものです
フォームをコントローラにポストバックすると、StartDate
フィールドはnullになります。
ここで私は、サーバーから取得レスポンスです:
"エラー":{ "開始日":{ "エラー":[ "値の\ u002707/2016分の10午前12時00分00秒 午前""}}}
ところで、サーバーに送信されるリクエストのAccept-Languageは "en-US"です。これは奇妙なものです。
UPDATE:
public class DateTimeModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
if (string.IsNullOrWhiteSpace(value.AttemptedValue))
return null;
DateTime dateTime;
var isDate = DateTime.TryParse(value.AttemptedValue, Thread.CurrentThread.CurrentUICulture,
DateTimeStyles.None, out dateTime);
if (!isDate)
{
bindingContext.ModelState.AddModelError(bindingContext.ModelName, "La fecha es válido.");
return DateTime.UtcNow;
}
return dateTime;
}
}
しかし、それは問題のように見えるに渡された日付の時間の一部であると私はこのように、DateTimeのためのカスタムモデルバインダーを使用しようとした
コントローラ。値「07/10/2016 12:00:00 a. m.
」は、「es-MX」および「en-US」カルチャのいずれの日付でも認識されません。一目で
07/10/2016は、es-MX(10月7日)とen-US(7月10日)の両方で有効な日付である必要があるため、この問題は文化に関連しているとは思わない –
@AndrésNava-.NET、私は知っていますが、web.configファイルと_Layoutページからes-MXカルチャを削除しても問題はありません。しかし、私がDatePickerのcultureをen-USに変更しただけでは、それはまだバインドされません。 – ataravati
@AndrésNava-.NETについては、私の更新をご覧ください。 – ataravati