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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.