我在路由表中有这个条目:
routes.MapRoute(null,
"instructions/new",
new { controller = "Instructions", action = "NewInstructions" },
new { httpMethod = new HttpMethodConstraint("GET") }
);
这种方法
[HttpGet]
public ActionResult NewInstructions(Client client)
{
var instructions = instructionService.Create(client);
return RedirectToAction("Instructions", new { id = instructions.Id });
}
和方法的链接
<a href="/instructions/new">create a new one</a>
在这种情况下,调用操作方法时client
参数不为null。相反,它显然是通过调用Client
的无参数构造函数来创建的。
但是,当我通过POST访问相同的操作方法时,client
参数已正确设置为null
。
如果区分GET和POST的请求未提供参数值并且每个参数的行为不同,这是DefaultModelBinder
的标准行为吗?
答案 0 :(得分:0)
您的网站如何转移到“NewInstructions”操作? 如果你来自动作返回View(“NewInstructions”)那么它可能带有前一篇文章的参数值。
但是,如果使用return RedirectToAction(...),则参数应该设置为null,如果是可选的则为null。