我有一个用户可以用来登录的登录页面,我在控制器中将其方法定义为HttpPost,当我尝试从浏览器访问它时,它显示没有找到文件,如果我删除HttpPost属性,它击中控制器并返回视图。它将形式值传递给控制器,如果我没有提及它的类型为HttpPost。这里是我的Login/SignIn.cshtml代码:无法调用方法,如果我提到它的属性为HttpPost
@model BOL.Player_Access
@using (Html.BeginForm("SignIn","Login",FormMethod.Post)){
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Sign In</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.PlayerEmail, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PlayerEmail, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.PlayerEmail, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="SignIn" class="btn btn-default" />
</div>
</div>
</div>
而我的LoginController代码是在这里
[AllowAnonymous] //This filter removes authorize filter for this controller alone and allow anonyomous request
public class LoginController : Controller
{
// GET: Login
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult SignIn(Player_Access plyr_obj)
{
return View();
}
}
发布您的完整代码。缺少结束大括号。 –