Request.QueryString无法识别或读取url中的查询字符串 [英] Request.QueryString not recognizing or reading query string in url

查看:306
本文介绍了Request.QueryString无法识别或读取url中的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一生无法弄清楚为什么Request.QueryString不能在URL中捕获查询字符串.当我将鼠标悬停在要单击的链接上时,它会在状态栏中显示正确的URL和查询字符串.但是,当我在调试模式下单击它时,它将在page_load tbat上运行一个方法,该方法应该从查询字符串中获取TableID.

当我到达检查Request.QueryString的行时,它就好像不存在一样经过.

有人可以给我指示吗?谢谢!

这是URL:

I cannot for the life of me figure out why the Request.QueryString is not catching the query string in the URL. When I hover on the link to be clicked, it shows the correct URL and query string in the status bar. However, when I click it in debug mode it runs a method on page_load tbat is supposed to get the TableID from the query string.

When I get to the line where it checks Request.QueryString it just passes over as if one does not exist.

Can someone give me some direction please? Thank you!

Here is the URL:

h t t p : //test.intranet.company.com/TableEditor/Default.aspx?TableID=19



这是代码:



Here is the code:

protected void Page_Load(object sender, EventArgs e)
   {
       TableID = getTableID();
       //TableID = 99;
       if (TableID != 0)
       {
           if (!IsPostBack)
           {
               _TableEditor = new TableEditor(TableID);
               if (_TableEditor != null)
               {
                    
                   
               }
           }
       }
private int getTableID()
    {
        int TableID = 0;
        if (!(string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["TableID"])))
        {
            TableID = (int.Parse)(HttpContext.Current.Request.QueryString["TableID"]);
        }
        return TableID;
    }

推荐答案

更正
中的代码
correct the code from

if (Request.QueryString.Count > 1)
                   { //code that does stuff
                   }









to

if (Request.QueryString.Count > 0)
                   { //code that does stuff
                   }


这篇关于Request.QueryString无法识别或读取url中的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆