【问题标题】:ASP.NET Response Redirect of URL Error; from static methodURL 错误的 ASP.NET 响应重定向;从静态方法
【发布时间】:2015-12-22 00:18:08
【问题描述】:

我正在开发 ASP.NET 3.5 应用程序。我有 $ajax jQuery 函数调用代码隐藏方法并发送员工 ID。

我希望 Response.Redirect 从此方法打开,但出现以下错误

$ajax 函数调用代码隐藏方法

$.ajax({
       url: 'AddUserInRole.aspx/GetRolesListFilteredByStaff_NotIn',
       type: "POST",
       data: JSON.stringify({ GivenStaffID: selectStaffIDToAddRole }),
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function (response) {
               alert(response.d);
        },
       failure: function (response) {
                alert(response.d);
                   }
       }).done(function (response) {
                   //
  });

代码隐藏方法

[WebMethod]
private static void GetRolesListFilteredByStaff_NotIn(string GivenStaffID)
 {
    Response.Redirect("/SelectRoleForStaff.aspx?staffID='GivenStaffID'");            
 }

我的第二个问题是如何从新上传页面中的 url 读取人员 ID

更新部分答案

我已经成功调用了 require 方法,但它没有重定向页面...

  [WebMethod]
  public static void GetRolesListFilteredByStaff_NotIn(string GivenStaffID)
    {
        HttpContext.Current.Response.Redirect("/SelectRoleForStaff.aspx?staffID="+GivenStaffID);            
    }

【问题讨论】:

  • 这是发生异常的 .asmx 文件吗?
  • 在更新部分答案...下查看我的问题。
  • 非常感谢............
  • 好的,让我重新表述一下。您使用该方法的文件是 aspx 还是 asmx 文件?

标签: c# jquery ajax webforms asp.net-3.5


【解决方案1】:

更新您的方法以返回要重定向的 url,例如:

[WebMethod]
public static string GetRolesListFilteredByStaff_NotIn(string GivenStaffID)
{
   return "SelectRoleForStaff.aspx?staffID=" + GivenStaffID;
}

在你的 ajax 成功中这样做:

success: function (response) {
               window.location = response;
               // OR
               window.location = response.d;
        },

【讨论】:

  • 在我的情况下,页面有回发并且 javascript 函数无法运行
猜你喜欢
  • 2017-02-23
  • 2011-11-23
  • 1970-01-01
  • 2018-04-02
  • 2018-06-27
  • 1970-01-01
  • 2014-07-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多