krv*_*rvl 2 c# asp.net-mvc http-redirect asp.net-mvc-3
在我的项目中,我有两个不同的控制器.
这是主要的一个:
public class Main : Controller
{
public ActionResult Index()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
这是另一个:
public class OtherOne : Controller
{
public ActionResult RandomAction()
{
return ... //more code here
}
}
Run Code Online (Sandbox Code Playgroud)
我应该在"OtherOne/RandomAction"中返回什么才能获得"主要/索引"操作的相同结果?
这很简单:
public class OtherOneController : Controller
{
public ActionResult RandomAction()
{
return RedirectToAction("Index", "Main");
}
}
Run Code Online (Sandbox Code Playgroud)
您的Controller类名必须是MainController和OtherOneController.如果要更改它,请查看以下文章: 在ASP.NET MVC中更改控制器名称约定
这是您的主控制器:
public class MainController : Controller
{
public ActionResult Index()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1534 次 |
| 最近记录: |