how to reload partial view in pop-up modal when opening it?


Hi, I wanted to clear the validation errors if I clicked the Create Button.

Because if I click the Close Button or The Black Shadow(Accidentally close the modal) behinds the Modal within the state of "Errors" in validation, if I click the create button again, the errors will still show, which should be removed as I am clicking back "Create" button.

Please check this link below as reference, the only thing I wanted to do is everytime i click Create Button, the partial view must clear all errors even it was from the previous transaction because sometimes I accidentally drop the modal. Thanks in Advance.

https://qawithexperts.com/article/asp.net/validate-pop-up-modal-using-ajaxbeginform-in-c-mvc/52  ...(Make this as reference)


Asked by:- Aileereal
1
: 9942 At:- 8/4/2017 11:02:06 AM
ASP.NET MVC BOOTSTRAP POP-UP MODAL







2 Answers
profileImage Answered by:- vikas_jk

You can load/re-load your partial view using Ajax on opening modal pop-up instead of opening it using button use this jquery ajax call to open it and call partial view

// when DOM is ready
$(document).ready(function () {

     // here #mybtn is id of button,clicking which you want to open pop-up
    $("#mybtn").click(function(){

         // show Modal
         $('#myModal').modal('show');

        $.ajax({
          url:"/Home/PartialView",
          type:'GET',
          success: function(data){
            //here frmEmp is id of div where you need to place returned html
            $("#frmEmp").html(data);
          },
          error:function(){ 
           alert("Error"); 
          }

         })
    });
})

it should work and whenever you click the button, it will reload partial view using ajax, so it will validation error messages also.

1
At:- 8/4/2017 4:28:55 PM
Good answer, basically, we need to load partial view again using jQuery AJAX, when we click on a button to open pop-up Modal. 0
By : neena - at :- 11/10/2021 11:35:51 AM


profileImage Answered by:- ashiqullah
$("table").on("click", "a[data-modal]", function () {
                   
                    $id = $(this).attr("id");
                    $('#myModalContent').load('/Master/RevenueCodeRowDetailsEdit/'+$id, function () {
                        $('#myModal').modal({
                            keyboard: true
                        }, 'show');
                        bindForm(this);
                    });
                    return false;

                })
1
At:- 8/12/2017 9:32:57 AM Updated at:- 8/12/2017 9:33:48 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use