views:

69

answers:

2

I'm a .net programmer, but new to mvc.

I created a new mvc page with a simple form on it - 2 textboxes and a submit button. Upon posting, it goes to my server side method, where the user info is entered into the db, and then I want to return the user to the same exact form but empty again.

When I use "return View("Index", new myIndexObject());" it returns the user to the same page with the form, but with the information he already filled out as if there was ViewState on the controls. How do i get rid of this ??

+8  A: 
return RedirectToAction("Index");
Darin Dimitrov
Thanks!!Surprisingly, It wasn't easy finding this solution on the net... :)
gillyb
+1  A: 

This solves the Problem but in Case the User or page needs to be Notified by the Message Tempdata can be used.

TempData["Message"] = "Your Message";
 return RedirectToAction("Index");

and In View Check like this

<%if (TempData["Message"] != null)
  { %>

  <div class="message"> <h2><%= TempData["Message"] as string %> </h2></div>
    <% } %>
This is a good idea.
Pretzel