模型的POST查询字符串和表单参数绑定 [英] Model binding on POST with query string AND form parameters

查看:313
本文介绍了模型的POST查询字符串和表单参数绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是形式,如果您发布的形式和它的操作在ASP.NET/MVC结合所定义的行为的查询参数你有表单数据?

What is the defined behavior for form binding in ASP.NET/MVC if you POST a form and its action has query parameters and you have form data?

例如:

<form action="my/action?foo=1" method="post">
     <input type="hidden" name="bar" value="2">
</form>

如果这样的形式提交应控制器同时获得或只是其中之一?

If such a form is submitted should the controller get both foo and bar or only one of them?

推荐答案

控制器将获得这两个值。默认的模型绑定将试图找到(无论是查询字符串或路由参数)或身体从两个URI的参数相匹配(并形成数据支持外的开箱)。

The controller will get both values. The default model binder will try to find matches for the parameters from both the URI (either query string or route parameters) or the body (and forms data is supported out-of-the-box).

这篇关于模型的POST查询字符串和表单参数绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆