MVC不会反序列化HttpGet变量

时间:2012-08-18 11:43:21

标签: asp.net-mvc parameters action

当我提交此网址时:

http://localhost:3333/User/GetAll?_dc=1345288777353&page=1&start=1&limit=25&callback=Ext.data.JsonP.callback2 

控制器不会反序列化PagingModel page。调试器显示page = null

public class PagingModel
{

    public string start { get { return _start; } set { _start = value; } }
    private string _start;

}

public class UserController : Controller
{

    [HttpGet]
    public JsonResult GetAll(PagingModel page)
    {
           ///////////////////
           //page is null.
           ///////////////////
    }
}

1 个答案:

答案 0 :(得分:1)

糟糕,重命名您的操作参数:

[HttpGet]
public JsonResult GetAll(PagingModel model)
{
   ///////////////////
   // model is no longer null
   ///////////////////
}

之所以这样,是因为您的请求中已经有page=1个查询字符串参数,使得默认模型绑定器变得狂暴,他们正在尝试将值1反序列化为PagingModel显然很难发生。