Link to home
Start Free TrialLog in
Avatar of zachvaldez
zachvaldezFlag for United States of America

asked on

Adding bootstrap call alert in C# code

After successfully inserting a record using the try,,catch.., I 'd like to use a bootstrap call to display the message as shown below.
     try
                {
                    // Do something
                    AppThis.InsertUpdateProduct();
             
            // I'd like to display the message calling a bootstrap alert  saying "Successfully added!"
                     
                }
                catch (Exception ex)
                {
                    // Log 
                    string strErrNum = ex.Message.ToString();

                    // Display message to users

                }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Bootstrap is a CSS library - you don't really call it. It is also client based so not accessible from the server.

Your best bet is to make an AJAX call to the server have the server return the response and then use JavaScript to manipulate the page (add text / classes etc) to achieve the desired result.
Avatar of zachvaldez

ASKER

This is for Mvc as  well
This is for Mvc as  well
I am not sure I understand this comment.
I 'm just learning MVC and I thought it is a good idea to do it the VIEW
I 'm just learning MVC and I thought it is a good idea to do it the VIEW
The code that runs in the browser is the RESULT of what is produced by MVC. The Controller routes the request, creates the model and sets up the view. The Model contains the data for the view and the View renders the final product - all of this happens on the server - where Bootstrap does not play a role.

When your MVC app has finished what it is doing the result is an HTML document that is sent to the browser - which then starts to parse the HTML.
As it parses the document it finds references to external resources (stylesheets, javascript libraries, images etc). Whenever it finds such a reference it initiates a new HTTP request to go and fetch those resources. These download in the background and when complete the browser incorporates them into the document.
Images are displayed, styles are applied.
In the case of Bootstrap - a request is made to whereever you are hosting the Bootstrap file (or CDN) and the bootstrap.css file is download. The styles contained in that file are read and applied to the DOM. Any elements that exist in the DOM (from the HTML file that was originally downloaded) that have Bootstrap styles are re-rendered with the new style from the bootstrap file.

All of this happens long after the MVC process is dead and burried. The only role MVC plays in this process is to render out the HTML with bootstrap classes that will ultimately acquire their final look and feel once the bootstrap CSS is merged into the DOM.
Since then I've read a few about MVC by this time  on a high level and I agree that bootstrap can only be applied in the View(htmls) when called to render.
 You are right Julian. I'm learning slowly asp.net core and MVC and entity framework to upgrade but I find it complicated process because it uses razor views and its syntax and helpers to render the html that maps from the model where the classes were set .
Thanks for elaborating.