0

我不确定这是否与 jqgrid 或 webservice/postback/JSON 问题有关,但我会尽量提供尽可能多的信息。

我正在发布带有 DateTime 字段的 jqgrid 模式弹出窗口。

当它从浏览器回传时,它会提交以下数据(如 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)更改为“11/05/2013 00:00:00”,而从客户端发送的shipdate 是 05-11-2013(这是正确的)。知道发生了什么吗?

4

1 回答 1

1

For datepicker you are using 'dd-mm-yyyy' format but on server side it converting to different format according to culture installed i.e. 'mm/dd/yyyy hh:mm:ss' with the time. If you need the same format what you are passing from jquery you need to parse the date on server side in specified format.

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));
于 2013-10-28T10:25:15.887 回答