How to pass parameter from one Controller to another in Asp.Net

Asked

Viewed 3,291 times

4

Hello, I have an object that I need to pass by parameter to another Controller through the RedirectToAction, used the TempData but after any page change it loses the reference, know of any solution so that it does not lose the reference? Or unless it’s done otherwise?

1 answer

6


Otherwise:

return RedirectToAction("OutraAction", "Controller", new { minhaClasse = /* objeto do tipo MinhaClasse */, area = "area"})

There yours Controller gets like this:

public ActionResult OutraAction(MinhaClasse minhaClasse) { ... }
  • Does Redirecttoaction accept another parameter? I need it for a controller from another area in this Redirecttoaction I forgot to mention.

  • @Luiznegrini Atualizei.

  • 1

    Perfect! Fighting Again!

  • 1

    @Luiznegrini Did it work? Could you accept the answer, for the benefit of the community?

  • @Dude, I don’t know why it didn’t work for me. It’s all right, action, parameters and so on... when I make the request he sends one SiteTeste.Models.Checkout.CheckoutResultModel which is the name of my object which I am passing as a string, strange not ? Then when I receive the parameter in Action creates an Exception null, did it fall into disuse ? use ASP.NET MVC5

  • @Leonardobonetti has a signature method that needs to pass htmlAttributes as null to work. Try this.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.