由于某种原因,GET和POST都触发了第一个操作。
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(FormCollection form)
{
// Login Stuff here... never gets reached!
}
我基本上是直接从MVC音乐商店示例中复制的。在另一个应用程序中尝试过,效果很好。
这是一个相当新的项目,在Visual Studio中使用了基本的MVC3项目模板,所有默认设置都没变。
我确保HTML输出指定了POST方法:
<form action="/Home/Login" method="post">
以下是我的Login.cshtml文件:
@{
ViewBag.PageTitle = "Login";
}
<section id="index">
<header>
<h2>Login</h2>
</header>
<content>
@using (Html.BeginForm("Login", "Home", FormMethod.Post))
{
<panel id="login">
<table>
<tr>
<td>Email:</td>
<td><input name="Email" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="Password" type="password" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Login" /></td>
</tr>
</table>
</panel>
}
</content>
</section>
在我提交表单后,我在浏览器中看到了这个URL:
http://localhost:51606/Home/Login?Email=我的邮箱地址&Password=我的密码
这些字段不应该出现在URL中!为什么我的表单被转换成GET请求?