【问题标题】:Response.Redirect inside JsonResultJsonResult 中的 Response.Redirect
【发布时间】:2015-03-02 05:22:08
【问题描述】:

我想将此查询字符串传递给某个 aspx 文件 (WebForm1.aspx)。但在这里我无法传递它。这是 MVC5 应用程序。一切正常,但 response.redirect 不起作用

 public JsonResult SubmitReportData(SelectedReportViewModel SubmitData)
    {
        Response.Redirect("~/Report/WebForm1.aspx?Id="+SubmitData.SelectedNode+"&stDate="+SubmitData.stDate+"&enDate"+SubmitData.enDate);



        //return Json(new { x = 1 });
       return null;

    }

【问题讨论】:

  • 您可以将路径作为字符串返回,并在 jquery 中使用 window.location.href='Your Path' 进行重定向。
  • @sehtaumesh 当我使用它时,它会显示“名称窗口在当前上下文中不存在”
  • 使用也可以试试这个 Response.Redirect("Your Path",True);
  • 我假设您是通过 AJAX 调用它的。默认情况下,大多数 AJAX 库只会将响应代码 200 视为成功,重定向是 302(通常)。请记住,处理响应的是 JavaScript,而不是浏览器,因此您需要在客户端使用 javascript 进行重定向。

标签: javascript c# asp.net json


【解决方案1】:

您可以在 Jquery 中将路径作为字符串返回并用作

window.location.href='Your Path';

重定向到另一个页面。

例如:

public JsonResult SubmitReportData(SelectedReportViewModel SubmitData)
{
   string path="~/Report/WebForm1.aspx?Id="+SubmitData.SelectedNode+"&stDate="+SubmitData.stDate+"&enDate"+SubmitData.enDate;
   return Json(path,JsonRequestBehavior.AllowGet);
}

【讨论】:

    猜你喜欢
    • 2010-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-02
    • 2012-01-30
    • 2014-10-17
    • 2011-08-21
    • 1970-01-01
    相关资源
    最近更新 更多