MVC 4 Post not hitting controller/action

I'm getting a really annoying issue in MVC 4 where my form posts aren't hitting the action I've specified. I've done this loads of times before and it worked fine but in my new project it doesn't seem to work at all.

It's a simple login page, with nothing fancy, just a user name and password field. Here's my code

HTML/Razor:

@model XYZ.Models.PageModels.LoginPageModel

<div class="login">
    <form class="left form">
        @using (Html.BeginForm("Login", "Account", FormMethod.Post))
        {
            <div class="form-group form-group-sm">
                <label class="control-label" for="UserName">User Name</label>
                @Html.TextBoxFor(model => model.UserName, new {@class="form-control", @placeholder="User Name"})
            </div>


            <div class="form-group form-group-sm">
                <label class="control-label" for="Password">Password</label>
                @Html.PasswordFor(model => model.Password, new {@class="form-control", @placeholder="Password"})
            </div>


            <div class="buttons right">
                <input type="submit" class="btn btn-primary btn-sm" value="Login" />
            </div>
        }
    </form>
</div>

You have nested forms in your markup. One you wrote yourself and the other one is generated from Html.BeginForm helper method. get rid of the outer one and you are good to go.

This should work fine.

<div class="login">
    @using (Html.BeginForm("Login", "Account"))
    {
        <div class="form-group form-group-sm">
            <label class="control-label" for="UserName">User Name</label>
            @Html.TextBoxFor(model => model.UserName, new { @class = "form-control", @placeholder = "User Name" })
        </div>


        <div class="form-group form-group-sm">
            <label class="control-label" for="Password">Password</label>
            @Html.PasswordFor(model => model.Password, new { @class = "form-control", @placeholder = "Password" })
        </div>


        <div class="buttons right">
            <input type="submit" class="btn btn-primary btn-sm" value="Login" />
        </div>
    }
</div>
链接地址: http://www.djcxy.com/p/36618.html

上一篇: 角色=“按钮”用于<a href

下一篇: MVC 4发布不会触及控制器/操作