【问题标题】:How to call a view of another controller in mvc4如何在 mvc4 中调用另一个控制器的视图
【发布时间】:2013-01-01 13:56:55
【问题描述】:
我有 2 个控制器,SearchController 和 DetailsController。
SearchController 包含 2 个包含表单的视图。
我想在 SearchController 中我的视图的 [HttpPost] 操作上重定向到详细信息控制器的视图
这可能吗???
【问题讨论】:
标签:
asp.net
razor
asp.net-mvc-4
razor-2
【解决方案1】:
如果您在第一个控制器中进行一些处理,然后将结果发送到另一个控制器,您可以尝试RedirectToAction。
查看
using(@Html.BeginForm("firstaction", "search", FormMethod.Post)){
// form stuff
}
控制器
public class SearchController
{
[HttpPost]
public ActionResult FirstAction()
{
// do initial processing in the first controller
// e.g persisting changed on Edit Screen
return RedirectToAction("SecondAction","Details");
}
}
public class DetailsController
{
public ActionResult SecondAction()
{
// do remaining processing in the first controller
// fetching data for a grid and displaying the grid of items
return View();
}
}