Converting/accessing QueryString values in ASP.NET

后端 未结 7 1597
长情又很酷
长情又很酷 2021-01-30 14:44

I\'m curious what everyone does for handling/abstracting the QueryString in ASP.NET. In some of our web apps I see a lot of this all over the site:

int val = 0;         


        
7条回答
  •  迷失自我
    2021-01-30 15:23

    Write some sort of a helper method (library) to handle it...

    public static void GetInt(this NameValueCollection nvCol, string key, out int keyValue, int defaultValue)
    {
        if (string.IsNullOrEmpty(nvCol[key]) || !int.TryParse(nvCol[key], out keyValue))
            keyValue = defaultValue;
    }
    

    Or something along those lines...

提交回复
热议问题