Suppose we have an ActionMethod with an int parameter:

 public ActionMethod Create(int? id) { . . . return View(); } 

And there is another ActionMethod (in the same controller) in which we redirect to the first method:

 public ActionMethod Index() { . . . . return RedirectToAction("Create"); } 

Question: how to pass a parameter (say id = 5) to Create(int? id) ?

  • Before you vote against it, think twice, this is “educational material” for Russian-speaking users. - SᴇM
  • so here it is enough to see the function reference: RedirectToAction - Grundy
  • one
    @Grundy Not so much there explains how to take a value in the controller as a parameter and even for experienced programmers there may be a lot of things obvious, but not for beginners, to whom this site is mainly directed. - SᴇM

1 answer 1

You can transfer as follows:

 public ActionMethod Index() { . . . . return RedirectToAction("Create", new { id = 5 }); } 

This will lead to redirection to the "Сайт"/"Контроллер"/Create/5.

  • one
    what redirect it will lead to depends on the settings of the route - Grundy
  • Yes, but here we are talking about the default settings, you can open another topic about this. - SᴇM
  • Do I redirect to /Caйт/Контроллер?id=5 - nick_n_a