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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With