tags:

views:

44

answers:

1

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 pattern 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?

+1  A: 

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.

HeavyWave
Thanks - it's like going back to classic ASP mindset - quite hard after years of ASP.NET webforms!
jules
A bit, yes, but since there is no logic it's all good, think about it as xslt.
HeavyWave