Hi
I want to define below code at only 1 place. Asof now i am writing it in each form
Hi
I want to define below code at only 1 place. Asof now i am writing it in each form
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
tag:
Then, use JavaScript or server-side logic to trigger this modal when needed.
3. Triggering the Modal:
To trigger the modal from different parts of your application, you can use JavaScript or server-side code to open it when required:
$('#deleteModal').modal('show');
This approach centralizes the modal code, making your application more maintainable and easier to manage. Now, you only need to update the modal in one place if any changes are required.
H Aman
I am using c# .net not MVC . I am trying to follow your example in another Post
Thanks
Aman GuptaPosted Aug 23, 2024, 6:10 AM
Hi Ramco,
To avoid duplicating the modal popup code in each form, you can centralize it in a single place and reuse it across your application. Here’s how you can do it:
1. Create a Partial View for the Modal:
You can create a partial view that contains the modal code. This partial view can be included in any page where you need the modal.
Steps:
Create Partial View:
Views/Sharedfolder (or any other folder) and selectAdd -> View._DeleteModal.cshtml.2. Include Partial View in Your Pages:
2. Alternative Using Layout or Master Page:
If you need this modal on many pages, you can add the modal code directly to your layout or master page, so it’s available throughout your application.
Steps:
Layout.cshtml(or master page if using WebForms).