2013-10-03 72 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我已经更新了我的答案和示例代码,用于转换您提到的所需日期格式。 –