user2214609
user2214609

Reputation: 4961

MVC redirect to a new action

This is my controller that performed database query and return the results to the form that call this controller:

[HttpPost]
public ActionResult Index(string File)
{
    var list = db.Objects.Where(x => x.protocol == File).ToArray();
    ViewBag.Files = list;
    //return View();
}

Now instead of return back the results the the same form i want to open new form so i have changed this to:

[HttpPost]
public ActionResult Index(string File)
{
    var list = db.Objects.Where(x => x.protocol == File).ToArray();
    ViewBag.Files = list;
    return RedirectToAction("ShowList", ???);
}

And create new method:

public ActionResult ShowList(string site)
{
    var list = db.Objects.Where(x => x.protocol == site).ToArray();
    ViewBag.Files = list;
    return View();
}

Currently i don't know how to send my string that received to the new method (ShowList)

Upvotes: 0

Views: 74

Answers (2)

Joffrey Kern
Joffrey Kern

Reputation: 6499

To pass a param to a your new action, you have to do this :

[HttpPost]
public ActionResult Index(string File)
{
    var list = db.Objects.Where(x => x.protocol == File).ToArray();
    ViewBag.Files = list;
    return RedirectToAction("ShowList", new { site = "yourparam" });
}

By this way, you will pass the param site to the ShowList method.

Hope it helps !

Upvotes: 2

user1928185
user1928185

Reputation: 112

You can wirte

return RedirectToAction(ControllerName, ActionName);

For example

return RedirectToAction("[ControllerName]", "ShowList");

Upvotes: -1

Related Questions