Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc ASP.NET MVC控制器方法输入参数-如何填充?_Asp.net Mvc_Jqgrid Asp.net - Fatal编程技术网

Asp.net mvc ASP.NET MVC控制器方法输入参数-如何填充?

Asp.net mvc ASP.NET MVC控制器方法输入参数-如何填充?,asp.net-mvc,jqgrid-asp.net,Asp.net Mvc,Jqgrid Asp.net,我试图理解ASP.NETMVCJQGrid示例。网格发出AJAX请求以获取其数据: http://[thesiteurl]/[ControllerName]/GetGridData?_search=false&nd=14&rows=10&page=1&sidx=Id&sord=asc 控制器方法为: public ActionResult GetGridData(GridSettings gridSettings) GET参数如何转换为GridSet

我试图理解ASP.NETMVCJQGrid示例。网格发出AJAX请求以获取其数据:

http://[thesiteurl]/[ControllerName]/GetGridData?_search=false&nd=14&rows=10&page=1&sidx=Id&sord=asc 
控制器方法为:

public ActionResult GetGridData(GridSettings gridSettings)

GET参数如何转换为GridSettings对象,以及如何使用其他类型对其进行更改?

ASP.NET MVC框架有一个内置的模型绑定器,用于执行此任务。(您也可以编写自定义模型绑定。)基本上,它最简单的功能就是检查传入数据的键/值对,并将其与路由操作方法的方法参数相匹配

检查请求时,您似乎有以下信息:

_search: false
nd: 14
rows: 10
page: 1
sidx: Id
sord: asc
例如,如果
Gridsettings
对象定义如下:

class GridSettings
{
    public string _search { get; set; }
    public int nd { get; set; }
    public int rows { get; set; }
    public int page { get; set; }
    public string sidx { get; set; }
    public string sord { get; set; }
}
然后,模型绑定器将能够相应地将传入参数映射到模型的属性

如果要定义另一个具有相同属性的类型,则可以使用该类型代替
GridSettings
。使用该类型,您可以添加更多属性以匹配任何要添加的客户机提供的值,您可以向模型内部添加更多逻辑,等等