使用asp .net mvc,我使用post和get提交了一个表单。在我的控制器中,我只能访问post参数,而不能访问GET参数。
这是我的HTML表单:
<form name="input" action="/account/Login/?test=123" method="post">
Username: <input type="text" name="username">
Lastname: <input type="text" name="lastname">
Password: <input type="text" name="password">
<input type="submit" value="Submit">
</form>我的控制器:
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public ActionResult Login(User model)
{
string test = Request.QueryString["test"]; // this is null
}我也尝试过我的控制器,但是没有用...
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public ActionResult Login(User model, string test)
{
// but "test" is also null
}发布于 2013-07-11 04:43:17
你的例子对我来说非常有效。在这两个操作变量中,我都得到了test=123
或者,您可以尝试使用Html.BeginForm() helper:
@using(Html.BeginForm("Account", "Login", new { test = "123" }, FormMethod.Post))
{
@:Username: <input type="text" name="username"/>
@:Lastname: <input type="text" name="lastname"/>
@:Password: <input type="text" name="password"/>
<input type="submit" value="Submit"/>
}发布于 2013-07-11 04:24:13
这不是HTTP动词的工作方式。
GET和POST不是两种传递数据的方式;它们是两种不同类型的HTTP请求。(只有POST才有有效负载)
您正在请求一个查询字符串参数。
但是,浏览器会从表单操作URL中剥离查询字符串参数。
HTTP请求根本不包含这些内容。
相反,您应该将其放在<input type="hidden">中。
https://stackoverflow.com/questions/17580168
复制相似问题