2013-10-03 23 views
0

我不確定這是與jqgrid相關還是web服務/回發/ JSON問題,但我會盡量提供儘可能多的信息。jqgrid表單發佈到webservice日期時間更改格式

我發佈jqgrid的模式彈出與DateTime字段。

當帖子來自其提交下列資料(如在Firebug看到的)瀏覽器的後退:

InStock Yes 
Name Desktop Computer 
Note note 
Ship 4 
ShipDate 05-11-2013 
id 1 
oper edit 



[WebMethod] 
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
public string UpdateOrder(DateTime ShipDate, string Name, Stock InStock,Ship Ship, string Note,int id) 
{ 
    return ""; 
} 

的jqGrid的colModel樣子..

colModel:[ 
    {name:'Id',index:'Id', width:60, sorttype:"int", editable: false}, 
    {name:'ShipDate',index:'ShipDate',width:90, editable:true, sorttype:"date",unformat: pickDate}, 
    {name:'Name',index:'Name', width:150,editable: true,editoptions:{size:"20",maxlength:"30"}}, 
    {name:'InStock',index:'InStock', width:70, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"},unformat: aceSwitch}, 
    {name:'Ship',index:'Ship', width:90, editable: true,edittype:"select",editoptions:{value:"4:FedEx;1:InTime;2:TNT;3:ARAMEX"}}, 
    {name:'Note',index:'Note', width:150, sortable:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"10"}} 
], 

和pickDate樣子

function pickDate(cellvalue, options, cell) { 
    setTimeout(function(){ 
     $(cell) .find('input[type=text]') 
       .datepicker({format:'dd-mm-yyyy' , autoclose:true}); 
    }, 0); 
} 

另外編輯形式風格如下(當編輯形式顯示出來)

function style_edit_form(form) { 
    //enable datepicker on "sdate" field and switches for "stock" field 
    form.find('input[name=ShipDate]').datepicker({format:'dd-mm-yyyy' , autoclose:true}) 
     .end().find('input[name=stock]') 
       .addClass('ace ace-switch ace-switch-5').wrap('<label class="inline" />').after('<span class="lbl"></span>'); 

然而,當數據是在服務器(ASMX服務)接收的日期時間(並按ShipDate)變化爲「2013年11月5日00:00:00」,而從客戶端發送的SHIPDATE是05 -11-2013(這是正確的)。任何想法發生了什麼?

+0

而你的問題是? – Mark

+0

對此表示道歉,問題以粗體突出顯示。 – daehaai

回答

1

對於日期選擇您使用的 'DD-MM-YYYY' 的格式,但在服務器端它根據文化轉換爲不同格式安裝即 'MM/DD/YYYY HH:MM:SS' 與時間。 如果你需要相同的格式,你從jQuery傳遞你需要在指定的格式解析服務器端的日期。

DateTime time = Convert.ToDateTime("11/05/2013 00:00:00"); 
Console.WriteLine(time); //Default format 
string format = "d/M/yyyy"; // Use this format 
Console.WriteLine(time.ToString(format)); 
+0

我有點理解你在這裏說什麼。你能舉個例子嗎? – daehaai

+0

我已經放置了服務器端和客戶端和服務器端代碼。我不能想到別的地方放在這裏。讓我知道你是否在尋找特定的東西。 – daehaai

+0

@ user25018我已經更新了我的答案和示例代碼,用於轉換您提到的所需日期格式。 –