sovan
sovan

Reputation: 479

MVC4 POST model from an action to another action skipping view

I need to POST a register model from another model without showing the register model to the user in MVC 4. Please suggest.

Upvotes: 1

Views: 861

Answers (3)

Daniele
Daniele

Reputation: 1938

Maybe is not the best approach, but you can put the model in hiddenfields

TempData example:

On redirecting Action:

TempData["model"] = model;
return RedirectToAction("DifferentAction");

On different Action

var myModel = (model)TempData["model"]
/* do register stuff */

Upvotes: 0

Erik Noren
Erik Noren

Reputation: 4339

Move your business logic out of the actions and into methods. Let your actions call those to do their work. Then instead of trying to abuse the framework to post data between actions, just call the method with the parameters you have.

Upvotes: 2

Daniel A. White
Daniel A. White

Reputation: 190925

I would store it in temp data and redirect instead of re-POSTing.

Upvotes: 0

Related Questions