You can add the result to ViewData. For example:
if (SaveToDbOK) { ViewData["Success"] = "Data was saved successfully."; // Do other things or return view }
In your opinion, you can place anywhere:
MVC2:
<% if (ViewData ["Success"]! = null) {%>
<div id = "successMessage">
<%: ViewData ["Success"]%>
</div>
<%}%>
MVC3:
@if (ViewData ["Success"]! = null) {
<div id = "successMessage">
@ViewData ["Success"]
</div>
@}
I used this approach in my last project to make the information returned from the server unobtrusive. Verifying that ViewData ["Success"] or ViewData ["Failure"] is done on the main page, divs are formatted using CSS, and jQuery code was used to hide notifications after 5 seconds.
Hi,
Huske
Husein roncevic
source share