0

I have existing modal popup which populates partial view dynamically on button click from parent view. In this partial view, there is button. on this button clicked, I am updating existing partial view with new partial view with below code .

$("body").on("click", "#btnAdd", function () {

            $('#EmployeeModal .modal-body').load('Employee/AddEmployee', function () {
                
            });
        });

this new partial view is nothing but another existing view but I have used as partial view using code -

return PartialView("EmployeeNew", employeeViewModel);

now this new partial view contains Form with MVC validation summary. but after submit click, required error message is not getting displayed. instead, control goes to Post action and form is breaking with null reference exception (some fields are blank).

but this form is not breaking when not used as Partial View (single parent view).

I have checked all necessary scripts and they exist - like jquery.validate.min.js, jquery.validate.unobtrusive.min.js and some bootstrap.js and css files.

what else I am missing?

SSD
  • 751
  • 1
  • 10
  • 30
  • 1
    You have to manually append jquery validation on the new form (loaded dynamically). See [this](https://stackoverflow.com/questions/9623407/how-to-reinitialize-jquery-unobtrusive-validation) and [this](https://stackoverflow.com/questions/3033910/jquery-how-to-dynamically-add-a-validation-rule) on how to do that. – ferikeem Jul 05 '21 at 06:59

0 Answers0