I'm very new to MVC, and just building my first site, using NerdDinner as an example. I'm wondering what is the best approach to displaying the result of a server-side process. eg on a screen where a user is asked to change their password - if the change fails validation then error messages are displayed as per NerdDinner p开发者_StackOverflowattern using the current view. If the change succeeds, ideally I want to stay on the same page, hide the change password controls and just display a "password change succeeded" message.
The options seem to be to either, redirect to a new view with the success message, or have hidden controls on the view and show/hide them using values returned in the ViewData. Is there another more elegant way of doing this?
I just do it like this:
<% if (ViewData["success"] != null)
{ %>
<div class="success">Huge Success!</div>
<% }
else
{ %>
Such things belong to the View, so you really shouldn't be thinking too hard about how to get it pretty. It's pretty by design, because it's in your view.
精彩评论