HttpPost方法未触发

时间:2015-09-09 08:20:45

标签: asp.net-mvc-5

我正在尝试实现登录页面。视图加载,单击提交按钮时,将发送EmployeeID和密码,但不会触发HttpPost方法,即使数据已发送到URL。

问题是HttpPost方法没有触发,我已尝试设置一个断点,但它没有中断。

这是我的观看代码:

@model Mike.Models.EMPLOYEE
....
<body style="background-color:white">
    <img src="~/img/thrupps.png" style="width: 300px; height: 200px; margin: 0px 490px 0px 490px; " />
    <div class="col-md-12">
        <form class="login-form">
            <div class="login-wrap">
                @using (Html.BeginForm("Login", "Account", FormMethod.Post))
                {
                <p class="login-img"><i class="icon_lock_alt"></i></p>
                <div class="input-group">
                    <span class="input-group-addon"><i class="icon_profile"></i></span>
                    @Html.TextBoxFor(a => a.EmployeeID, "EmployeeID", htmlAttributes: new { @class = "form-control" })
                </div>
                <div class="input-group">
                    <span class="input-group-addon"><i class="icon_key_alt"></i></span>
                    @Html.TextBoxFor(a => a.employee_password, "Password", htmlAttributes: new { @class = "form-control" })
                </div>

                <input type="submit" id="button" class="btn btn-lg btn-success btn-block " value="Login"/>

                }
            </div>
        </form>
    </div>
</body>

这是控制器代码:

    [AllowAnonymous]
    public ActionResult Login(string returnUrl)
    {
        ViewBag.ReturnUrl = returnUrl;
        return View();
    }

    //
    // POST: /Account/Login
    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]

   public ActionResult Login(string returnUrl, string Password, int EmployeeID)
    {
        EMPLOYEE employee = new EMPLOYEE();

        if (employee == null)
        {
            return View("Login","Account");
        }
        else
        {
            if(employee.employee_password.Equals(Password))
            {
                return View("Index", "Home");
            }
                else
                {
                   return View("Login","Account"); 
                }
        }

    }

1 个答案:

答案 0 :(得分:1)

您有嵌套的表单,这些表单是无效的HTML并且不受支持。您需要删除外部<form class="login-form">代码。