tags:

views:

3779

answers:

3

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

+5  A: 

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

CodeClimber
You absolute legend! Thanks a lot, brought a smile to my face!
Shahin
+1  A: 

If your Index method on the controller does a return View("Index"); then just call the Index method with any parameters it requires. Then the method will populate the ViewData reuired by the Index View.

Matthew
+1  A: 

But If the view is it in another controller how to?

Julien
You can call an action on another controller using RedirectToAction(string actionName, string controllerName, object routeValues).
Spear