js中获得数据
1 "ajax": { 2 "type": "GET", 3 "url": "/Home/LoadPrice", 4 "dataSrc":"dataSet" 5 }, 6 "columns": [ 7 { "data": "region" }, 8 { "data": "hbFh" }, 9 { "data": "price" } 10 11 ],
会传一个形如以下格式的URL给HomeControlle中的LoadPrice
请求 URL: http://localhost:63938/Home/LoadPrice?draw=1&columns%5B0%5D%5Bdata%5D=region
&columns%5B0%5D%5Bname%5D=
&columns%5B0%5D%5Bsearchable%5D=true
&columns%5B0%5D%5Borderable%5D=true
&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=
&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false
&columns%5B1%5D%5Bdata%5D=hbFh
&columns%5B1%5D%5Bname%5D=
&columns%5B1%5D%5Bsearchable%5D=true
&columns%5B1%5D%5Borderable%5D=true
&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=
&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false
&columns%5B2%5D%5Bdata%5D=price
&columns%5B2%5D%5Bname%5D=
&columns%5B2%5D%5Bsearchable%5D=true
&columns%5B2%5D%5Borderable%5D=true
&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=
&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false
&order%5B0%5D%5Bcolumn%5D=2
&order%5B0%5D%5Bdir%5D=asc
&start=0&length=99
&search%5Bvalue%5D=
&search%5Bregex%5D=false
&_=1498633233102
通过定义参数
public IActionResult LoadPrice(int draw,int length,int start)
在LoadPrcice可以获得 start,draw,length的值,其他参数的名称中包含C#命名规则中不支持的字符所以无法取得值,这个有什么好方法解决?
改成Post试试?
DataTables是封装好的jQuery插件,它和后端传递数据时是通过url参数传值的。现在它的参数名称有一部分不符合C#命名规则,导致C#无法获得相应参数的值。Post中的url参数也是一样的情况。
@罗伯特·福特: http://m.datatables.net/manual/server-side Api里有提到改成post时 那一大坨参数都会post形式提交 这时你在action定义参数类接收 只要写需要的属性即可