2

I have an action which I need to post forward onto another action if it meets certain conditions, but I am unable to preserve the form data when passing through to the next action.

The receiving action accepts a FormCollection, which the sending action

Currently, I am doing a return RedirectToAction("action","controller", form). And I can determine that the form variable has keys before it redirects (form.HasKeys() = true).

When the action is hit however, the FormCollection is empty (form.HasKeys() = false).

Any ideas? Is there a 'PostToAction' method that I am missing?

FYI: I am using ASP.NET MVC Beta. Many thanks!

Edit: For those who have this problem, please look into the PRG Pattern. This is the actual term of what I was looking to do which also enables pretty urls.

Dan Atkinson
  • 11,391
  • 14
  • 81
  • 114

2 Answers2

2

I would refactor the two controllers and put the common code into a helper or into a common base class. That way the actions in the two controllers can delegate to the common code.

ewalshe
  • 3,684
  • 2
  • 19
  • 19
2

When RedirectToAction is called it will make an HTTP redirection and it will make a GET to the other action URL. If you need to reuse the code from another controller I'd do what ewalshe suggest, move the common to a BaseController or a business service and make both actions delegate to it.

This links may help:

Community
  • 1
  • 1
Eduardo Campañó
  • 6,778
  • 4
  • 27
  • 24