Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将Request.QueryString中的值获取到另一个方法中_C#_Asp.net_Methods_Request - Fatal编程技术网

C# 将Request.QueryString中的值获取到另一个方法中

C# 将Request.QueryString中的值获取到另一个方法中,c#,asp.net,methods,request,C#,Asp.net,Methods,Request,我正在尝试将nom的值输入StudentListByFilter(),有人能帮我吗?默认值返回为0。我想将查询字符串(nom)插入StudentAttendanceList()中,但值为0 public partial class AttedanceManagementJT : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //int nom = Conver

我正在尝试将nom的值输入StudentListByFilter(),有人能帮我吗?默认值返回为0。我想将查询字符串(nom)插入StudentAttendanceList()中,但值为0

public partial class AttedanceManagementJT : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //int nom = Convert.ToInt32(Request.QueryString["ActivityId"]);
    }
    [WebMethod(EnableSession = true)]
    public static object StudentListByFilter()
    {
        return ApplyMethods.StudentAttendanceList(Convert.ToInt32(HttpContext.Current.Request.QueryString["ActivityId"]));
    }
无法将值“传递”给另一个方法的原因是它不是另一个方法。这是一个“页面方法”,在单独的请求中运行。在第二个请求中,没有“ActivityId”查询字符串参数

但是,您可以通过会话状态将查询字符串参数从第一个请求传递到第二个请求:

public partial class AttedanceManagementJT : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int nom = Convert.ToInt32(Request.QueryString["ActivityId"]);
        Session["nom"] = nom;
    }

    [WebMethod(EnableSession = true)]
    public static object StudentListByFilter()
    {
        return ApplyMethods.StudentAttendanceList(
            Convert.ToInt32(HttpContext.Current.Session["nom"]));
    }
}

在我的情况下,调用页面时有或没有一些参数,会话将保存上一次调用的值,这将导致问题。 我发现在我的例子中,更稳定的解决方案是在页面上有一些隐藏字段,在pageload上保存参数,然后将该值作为附加参数从客户端javascript传递给webmethod。

Convert.ToInt32(HttpContext.Current.Request.QueryString[“ActivityId”])那么这个方法在StudentListByFilter()中真的有用吗?(y)答案是肯定的。