2

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>
Ghazanfar Khan
  • 3,648
  • 8
  • 44
  • 89

1 Answers1

0

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

Using Ajax.BeginForm with ASP.NET MVC 3 Razor

Community
  • 1
  • 1
turhanco
  • 941
  • 10
  • 19