【问题标题】:Return action to action in asp.net mvc在 asp.net mvc 中返回动作到动作
【发布时间】:2017-08-30 06:04:52
【问题描述】:

为什么我在使用 jQuery 加载函数调用插入操作时从插入操作返回到 InsertUpdate() 不起作用。它显示以下错误:

未找到局部视图“插入”或没有视图引擎支持 搜索到的位置。搜索了以下位置:

~/Views/AppClient/Insert.aspx
~/Views/AppClient/Insert.ascx
~/Views/Shared/Insert.aspx
~/Views/Shared/Insert.ascx
~/Views/AppClient/Insert.cshtml
~/Views/AppClient/Insert.vbhtml
~/Views/Shared/Insert.cshtml
~/Views/Shared/Insert.vbhtml

public ActionResult Insert()
{
   return InsertUpdate();
}
private ActionResult InsertUpdate()
{
   return PartialView();
}

【问题讨论】:

  • 不工作是什么意思?错误是什么?你怎么回来,还有很多问题你还没有解释清楚

标签: asp.net-mvc


【解决方案1】:

即使调用的实际操作是InsertUpdate(),调用它的上下文仍然是Insert() 方法(主要是因为您的路由值中的action 仍然是insert)。

因此,当您在调用 PartialView() 时未指定要呈现的视图时,视图的名称基于当前路由数据。

试试这个:

return PartialView("InsertUpdate");

或者在调用InsertUpdate()时手动更改路由数据:

public ActionResult Insert()
{
    this.RouteData.Values["action"] = "InsertUpdate";

    return InsertUpdate();
}

【讨论】:

    猜你喜欢
    • 2016-12-04
    • 2011-04-14
    • 2014-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-26
    • 2021-04-22
    • 2023-03-27
    相关资源
    最近更新 更多