【发布时间】:2017-07-24 16:48:50
【问题描述】:
我有一个用户可以用来登录的登录页面,我在控制器中将其方法定义为 HttpPost,当我尝试从浏览器访问它时,它显示未找到文件,如果我删除 HttpPost 属性它会命中控制器并返回视图。即使它将表单中的值传递给控制器,如果我没有提到它的类型为 HttpPost 。这是我的 Login/SignIn.cshtml 代码:
@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();
}
}
【问题讨论】:
-
发布您的完整代码视图。缺少端花括号。
标签: asp.net-mvc controller http-post action-filter