先贴代码
Html:
1 <div class="dx-field"> 2 <div id="lblDocDescription" class="dx-field-label">文档名称</div> 3 <div class="dx-field-value"> 4 <div id="txtDocDescription"></div> 5 </div> 6 </div> 7 <div class="dx-field"> 8 <div id="lblDocCategory" class="dx-field-label">文档类型</div> 9 <div class="dx-field-value"> 10 <div id="cboDocCategory"></div> 11 </div> 12 </div> 13 <div class="dx-field"> 14 <div id="lblDocDiscipline" class="dx-field-label">专业</div> 15 <div class="dx-field-value"> 16 <div id="cboDocDiscipline"></div> 17 </div> 18 </div>
html我就贴一部分,不全部都贴出来了
JavaScript:
1 var DocOrders = new DevExpress.data.CustomStore({ 2 load: function (loadOptions) { 3 var deferred = $.Deferred(), args = {}; 4 args.DocName = $('#txtDocName').dxTextBox("option", "value"); 5 args.DocDes = $('#txtDocDescription').dxTextBox("option", "value"); 6 args.DocCategory = $('#cboDocCategory').dxDropDownBox("option", "value"); 7 args.DocDiscipline = $('#cboDocDiscipline').dxSelectBox("option", "value"); 8 args.DocVersion = $('#txtDocVersion').dxTextBox("option", "value"); 9 args.DocRevVersion = $('#txtDocRevVersion').dxTextBox("option", "value"); 10 $.ajax({ 11 url: "Layout/GetDocument", 12 data: args, 13 success: function (result) { 14 deferred.resolve(result); 15 }, 16 error: function () { 17 deferred.reject("搜索失败"); 18 }, 19 timeout: 30000 20 }); 21 return deferred.promise(); 22 } 23 });
Controller:
1 public JsonResult GetDocument(string DocName,string DocDes,string DocCategory,string DocDiscipline,string DocVersion,string DocRevVersion) 2 { 3 var doccate=DocCategory; 4 }
说明下我运行的结果,Controller中DocCategory的值现在是NULL,其余的值传递都正常,大家不用怀疑选择器的事情,在JavaScript中args.DocCategory的值肯定是有的,因为我用alert测过了,无论是alert(args.DocCategory)还是alert($('#cboDocCategory').dxDropDownBox("option", "value"))都是有值的,但传到Controller中就是null,我直接args.DocCategory="123"倒是可以传过去,疯了,有人知道可能哪里出问题了么?
{ "DocName":args.DocName, "DocDes":args.DocDes, "DocCategory":args.DocCategory, "DocDiscipline":args.DocDiscipline, "DocVersion":args.DocVersion, "DocRevVersion":args.DocRevVersion }
data这样传值试下,ajax之前console.log(args);浏览器点开这个对象看对象属性值在不在(我知道你说alter过,但我还是想看看args对象的各个属性情况)
OMG,给你看下结果,我就试了2个参数,因为2个就够了
貌似DocCategory是个数组,不能在Controller里面用string?
好了,参数赋值里面加一句判断即可,多谢。
1 if ($('#cboDocCategory').dxDropDownBox("option", "value") != null) { 2 args.DocCategory = $('#cboDocCategory').dxDropDownBox("option", "value")[0]; 3 } else { 4 args.DocCategory = ""; 5 }
@星尘之泪: 嗯嗯 O(∩_∩)O
@星尘之泪: string是字符串类型,如果要接收数组类型,你可以试试string[]
打开浏览器开发者工具,看一下请求时发出的数据是否有问题
。。。太自信了。。。