i am making an app using aspnet identity in which login page is displayed in a bootstrap modal all the validations are working fine if fields empty.but issue is modal is not closing and other page data is displaying in the same modal, which looks so weired.
what i want send data from login page to desired page, if any errors they should be displayed on modal if no errors then modal should close successfully and that page data shows in appropriate manner. and during this process modal should not close or any other barrier which can stop user interaction to my site
if i set data dismiss property then modal is closing no submitting happens.
please help me
Naimish MakwanaPosted Feb 2, 2024, 5:03 AM
If you want to keep the modal open if there are validation errors, and close it only when the form is successfully submitted. Here’s a general approach you can take:
Handle form submission with AJAX: Instead of a regular form submission, use AJAX to submit the form. This allows you to control what happens after the form is submitted without reloading the page.
Return validation errors in the response: If there are validation errors, return them in the response from your server-side code. You can return a JSON object with an
errorsproperty containing the validation errors.Display validation errors in the modal: If the response contains validation errors, display them in the modal. You can use JavaScript/jQuery to update the modal content with the validation errors.
Close the modal on successful submission: If the form is successfully submitted (i.e., there are no validation errors), you can close the modal. You can do this by adding a line of code in your AJAX success callback to close the modal.
Here’s a basic example using jQuery:
In this example, replace
#yourFormwith the id of your form, and#yourModalwith the id of your modal. The#errorContaineris where you want to display the validation errors in your modal.Thanks