简体   繁体   中英

asp.net mvc 4 registration inside bootstrap modal plugin

I am performing registration inside bootstrap 3 modal components.I create a partial view for registration and render that inside bootstrap modal. I am performing validation there also.Problem is that if I submit wrong data or empty data modal disappers on submit button click . I want that it stays there if data is not valid and show validation errors there.How I customize that?

Here is my partial view

      @using (Html.BeginForm("", "", FormMethod.Post, new { @class = "form-signin" }))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary()
           <fieldset>
            <legend class="form">Registration Form</legend>
            @Html.TextBoxFor(m => m.UserName, new { @class = "form-control", placeholder = "Email Address" })
            @Html.PasswordFor(m => m.Password, new { @class = "form-control", placeholder = "Password" })
            @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control", placeholder = "Confirm Password" })
            <input type="submit" value="Register" style="margin-top:10px;" class="btn btn-lg btn-primary btn-block" />
        </fieldset>
    }

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

and here is the modal

<div id="myModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Registration</h4>
            </div>
            <div class="modal-body">
            @Html.Partial("_Register")
              </div>

        </div>
    </div>
</div>

You have to use Ajax.BeginForm(). Here is the way how can you achieve it.

Using Ajax.BeginForm with ASP.NET MVC 3 Razor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM