Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide action "success" feedback to user in ASP.NET MVC?

Tags:

asp.net-mvc

Lets say we have an Edit View to edit our data, and we want to let the user know the result of their edit ie. to confirm that it was indeed saved successfully on the Model.

One solution is to assign a message to ViewData in the Edit Controller action method, and then use the View to display the message back to the user.

e.g. In the Edit Controller action method:

ViewData["EditResult"] = "All is well in the world.";

... and somewhere in the View:

<%= ViewData["EditResult"] %>

This is nice and easy, but is this the best way to provide feedback from the controller to the View? What are some other alternatives as I seem to be borderline on putting presentation type stuff in the Controller.

like image 422
saille Avatar asked Nov 05 '22 21:11

saille


1 Answers

A very simple approach would be to pass some boolean or other status flag to the view as part of the model data; the view can then render that information as it sees fit.

Alternatively, you might want to consider having separate views for success vs. failure, since you may very well be rendering totally different content in each case.

like image 171
Rob Avatar answered Nov 15 '22 01:11

Rob