Mark
Mark

Reputation: 69920

Set a ModelState to an ActionResult in ASP.Net MVC

In a View, I've created a <form> that posts some data to another Controller, which is different from that one that redirected me to the View. In this second controller, i perform some data validations and then, if errors are found, I need to redirect the user again to the source View but with the edited ModelState (so that i can show the validation errors).

Any tips?

Upvotes: 0

Views: 530

Answers (2)

rrejc
rrejc

Reputation: 2682

Yes, you can use PRG pattern like Darin said.

Cheers!

Upvotes: -1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038750

Instead of redirecting back to the original controller can't you just return View("~/Views/FirstController/Index.aspx")? Another option would be to store the model inside TempData before redirecting and fetching it back from TempData in the first controller if available.

Upvotes: 3

Related Questions