ASP.NET MVC return a different view

I have a view which contains a form, the form posts and the data gets processed etc, then I want to return the view Index, so return view("Index");

however this will then complain about my ViewData not existing, I get the feeling that the controller code under Index() isn't being processed which adds the list it requires to the ViewData, anyone know what's wrong?

Thanks

edit: Apparently it's done to prevent recursion.. in which case, I'm lost as to what to do without repeating all my ViewData stuff both Controllers

Answers


I think you should have two actions: one that processes the form submission, and another one that collects data for the view. Once the form has been processed, you call return RedirectToAction("Index") and you are done. I hope I understood what you meant by this.


Need Your Help

Adding tooltips to line graph data points AFTER lines animate

javascript d3.js line

I have a basic line graph with two lines. When I click a button, one of the two lines will draw on the graph.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.