I am using MVC 3 Razor for my website. My requirement is that I want to show display friendly messages to the user on Su开发者_StackOverflow社区ccess/Failure of the request, on the View itself, don't want to re direct the user to another View. I want like I could customize the display like Green color with some Success image and Red color for failure and respective image.
What would be the best approach?
It sounds like you want to know if a request failed or succeeded based on user input. If you are posting data to the server, you want to consider using the AjaxHelper
the BeginForm
-method takes an argument of AjaxOptions
.
On the AjaxOptions
you can specify OnSuccess and OnError among others and when one of these are called, you can call the corresponding JavaScript.
If this on the other hand is not enough, you might want to inspect the data that came from the server and based on that decide if the request succeeded or not, you want to use jQuery
and their ajax-components. Here's an example of how to use the jQuery
-option:
$.post("/MyController/MyAction", function(data) {
// Check what data contains.
});
精彩评论