【问题标题】:MVC3 load controller in a View视图中的 MVC3 负载控制器
【发布时间】:2011-03-24 23:07:40
【问题描述】:

我正在尝试加载一个页面,并且在该视图中我想从检索信息的不同控制器加载另一个视图。 我可以用: @Html.Partial("其他视图") 这适用于不需要数据但我希望页面检索数据的页面,因此使用: @Html.Action("其他视图") 我认为应该工作,但没有,我得到一个 HttpException

“执行处理程序'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'的子请求时出错。”

一定有办法做到这一点,

谢谢 凯尔夫

【问题讨论】:

    标签: asp.net-mvc-3 view controller


    【解决方案1】:

    使用

     @Html.Action("otherView", "otherController", new { vm = viewModel })
    

    并在控制器中创建一个动作

    public ActionResult otherView(otherViewModel vm)
    {
        return PartialView("otherView", vm);
    }
    

    【讨论】:

      【解决方案2】:

      听起来您正在寻找 RenderAction。

      Here's the first article I found on the subject.

      【讨论】:

      • Action 或 RenderAction 大致相同。唯一的区别是结果是在响应中呈现,还是作为字符串返回。看看这个:Html.RenderAction and Html.Action
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多