Asp.Net MVC 5,查看不回发给控制器

时间:2015-11-04 13:31:58

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 razor

我正在使用Asp.Net MVC 5创建一个简单的登录表单。一切都很好但是当我在提供用户ID和密码后单击提交按钮时,视图不会返回到所需的控制器操作(LogIn)。这是行动:

SELECT COUNT(id) AS GLOBELAMOUNT,
       COUNT(CASE WHEN YEAR=2000 THEN 1 END) AS  HIREDIN2000,
       COUNT(CASE WHEN YEAR=2002 THEN 1 END) AS  HIREDIN2002 
FROM EMP;

和视图:

        [HttpPost]
        public ActionResult LogIn(User user)
        {
            var auth_user = CheckAuthentication(user);
            if(auth_user!=null)
            {
                Session["user"] = new User() { UserId = user.UserId, Name = user.Name };
                return RedirectToAction("Index", "User");
            }
            return View();
        }
        [AllowAnonymous]
        public ActionResult LogIn()
        {
            return View();
        }

这是我完整的用户控制器:

@model FinancialManagement.Models.User

@{
    ViewBag.Title = "LogIn";
}

<h2>LogIn</h2>

@using (Html.BeginForm("LogIn", "User", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    <div class="form-horizontal">
        <h4>User</h4>
        <hr />
        @Html.ValidationSummary(true)
        <div class="form-group">
            @Html.LabelFor(model => model.UserId, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.UserId)
                @Html.ValidationMessageFor(model => model.UserId)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Password, new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Password)
                @Html.ValidationMessageFor(model => model.Password)
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Log In" class="btn btn-default" />
            </div>
        </div>
    </div>
}
<div>
    @Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

1 个答案:

答案 0 :(得分:-2)

尝试指定视图的名称和您的模型:

return View("NameOfView", YourModel);

如果没有工作,请填写绝对路径:

return View("~/Views/FolderName/ViewName.cshtml");