MVC重定向到新动作

时间:2022-05-22 11:12:39

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)

目前我不知道如何将收到的字符串发送到新方法(ShowList)

2 个解决方案

#1


2  

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.

通过这种方式,您将param站点传递给ShowList方法。

Hope it helps !

希望能帮助到你 !

#2


-1  

You can wirte

你可以

return RedirectToAction(ControllerName, ActionName);

return RedirectToAction(ControllerName,ActionName);

For example

例如

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

return RedirectToAction(“[ControllerName]”,“ShowList”);

#1


2  

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.

通过这种方式,您将param站点传递给ShowList方法。

Hope it helps !

希望能帮助到你 !

#2


-1  

You can wirte

你可以

return RedirectToAction(ControllerName, ActionName);

return RedirectToAction(ControllerName,ActionName);

For example

例如

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

return RedirectToAction(“[ControllerName]”,“ShowList”);