cjo*_*136 118 c# asp.net-mvc
我一直在寻找一些方法来重定向到Index另一个控制器的视图.
public ActionResult Index()
{
ApplicationController viewModel = new ApplicationController();
return RedirectToAction("Index", viewModel);
}
Run Code Online (Sandbox Code Playgroud)
这就是我现在尝试的.现在我给的代码有一个ActionLink链接到我需要的页面Redirect.
@Html.ActionLink("Bally Applications","../Application")
Run Code Online (Sandbox Code Playgroud)
mus*_*fan 254
使用带有控制器名称的重载...
return RedirectToAction("Index", "MyController");
Run Code Online (Sandbox Code Playgroud)
和
@Html.ActionLink("Link Name","Index", "MyController", null, null)
Run Code Online (Sandbox Code Playgroud)
jav*_*iry 26
尝试:
public ActionResult Index() {
return RedirectToAction("actionName");
// or
return RedirectToAction("actionName", "controllerName");
// or
return RedirectToAction("actionName", "controllerName", new {/* routeValues, for example: */ id = 5 });
}
Run Code Online (Sandbox Code Playgroud)
在.cshtml视野中:
@Html.ActionLink("linkText","actionName")
Run Code Online (Sandbox Code Playgroud)
要么:
@Html.ActionLink("linkText","actionName","controllerName")
Run Code Online (Sandbox Code Playgroud)
要么:
@Html.ActionLink("linkText", "actionName", "controllerName",
new { /* routeValues forexample: id = 6 or leave blank or use null */ },
new { /* htmlAttributes forexample: @class = "my-class" or leave blank or use null */ })
Run Code Online (Sandbox Code Playgroud)
注意事项使用null不建议在最终表达,是更好地使用空白new {}的,而不是null
Wou*_*ort 15
您可以使用以下代码:
return RedirectToAction("Index", "Home");
Run Code Online (Sandbox Code Playgroud)