2011-10-06 57 views
0

我有一個自定義編輯器模板,用於在telerik網格中插入mvc3剃鬚刀的車輛部件。編輯器模板包含一個日期時間字段。在插入新的車輛部件時,日期時間字段不正確,格式改變。自定義網格編輯器模板中的telerik datetime格式未正確傳遞給控制器​​

例如,如果我在控制器中插入「06/10/2011」,即第6天,第10天和2011年,則模型中的日期時間字段爲「10/06/2011」,即第10天6個月和一年211我使用Telerik的日期選擇器

基本上日期和月份正在成爲提交給控制器後切換

我在我的代碼,我想過去時間字段沒有其他實例一個問題,所以我相信問題是,我正在使用自定義編輯器模板的事實...

這是網格代碼:

@(Html.Telerik().Grid<VehiclePartsViewModel>() 
    .Name("VehiclePartsViewModel") 
    .ToolBar(commands => 
    { commands.Insert(); 
    }) 
    .DataKeys(keys => keys.Add(c => c.Id)) 
    .ClientEvents(events => events.OnRowDataBound("onRowDataBound")) 
    .DataBinding(dataBinding => dataBinding 
     .Ajax() 
      .Insert(MVC.Vehicles.CustomCoverage._InsertPart().GetRouteValueDictionary()) 
      .Select(MVC.Vehicles.CustomCoverage._SelectPart().GetRouteValueDictionary()) 
      .Update(MVC.Vehicles.CustomCoverage._SavePart().GetRouteValueDictionary()) 
      .Delete(MVC.Vehicles.CustomCoverage._DeletePart().GetRouteValueDictionary()) 
     ) 
    .Columns(columns => 
    { 
     omitted.. 
    }) 
    .Footer(false) 
    .Editable(editing => editing.Mode(GridEditMode.PopUp)) 

簡化編輯模板是:

<div> 
    @Html.LabelFor(v => v.ItemId, new { @class = "uc-caption"}) &nbsp; 
    @Html.EditorFor(v => v.ItemId) 
</div><br /> 
<div> 
    @Html.LabelFor(v => v.InstallDate, new { @class = "uc-caption"}) &nbsp; 
    @Html.EditorFor(v => v.InstallDate, new { Modifiable = true }) 
</div> 

我也使用了日期時間的編輯模板,但我不相信這個問題是在這裏:

@( 
    Html.Telerik().DatePicker() 
    .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)) 
    .HtmlAttributes(new { id = ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty) + "_wrapper" }) 
    .ShowButton(true) 
    .Value(Model.HasValue ? Model.Value : new DateTime()) 
    .ClientEvents(events => events.OnChange("onChangeDatePicker")) 
    .InputHtmlAttributes(new { style = "width:100%"}) 
    .Enable(ViewData["Modifiable"] != null ? (bool)ViewData["Modifiable"] : true) 

感謝

回答

2

好了,所以我終於能夠與Telerik的解決這個..似乎有是一個問題與全球化設置爲true。你必須在它之前添加一行。這是我的_layout.cshtml貌似現在..

@(Html.Telerik().ScriptRegistrar() 
     .OnDocumentReady(@<text></text>) //Telerik: This is required because there is still no Telerik components on the page and jQuery(document).ready will not be rendered and the globalization will not work 
     .Globalization(true)  
1

您可能遇到了應用程序的全球化/本地化問題。 不同的文化混雜在一起。

我張貼浮點值時,有同樣的問題,並通過添加這種方法的global.asax.cs解決了這個問題:

protected void Application_AcquireRequestState(object sender, EventArgs e) 
{ 
     System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en"); 
     System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en"); 
} 
+0

感謝您的回答,其實我試過,但沒有取得任何成功,似乎無論我將CurrentUICulture設置爲什麼,在某個時候它都會重置回到美國。我只能在視圖中出現局部視圖時纔會出現此問題,並且網格處於局部視圖中。部分視圖然後在插入時使用編輯器模板。非常奇怪的問題,仍然得到telerik的幫助... – Amith

相關問題