正确获取get参数
.net獲取參數(shù)和asp的可是截然不同了,因為他的轉(zhuǎn)換會在沒有參數(shù)的情況下報錯。
private int getParameter()? //獲取傳遞過來的參數(shù)
{
??? int currentID;
??? int getID;
??? if (Request.QueryString["ID"] != null && Int32.TryParse((string)Request.QueryString["ID"], out getID))
??? {
??????? currentID = getID;
??? }
??? else
??? {
??????? currentID = 97;
??? }
??? return currentID;
}
注意:
比如,你要將一個字符串解析為整數(shù),其函數(shù)原型為:int.TryParse(string string, out int result),代碼如下:
int value = 0;
if(!int.TryParse(str, out value)
{
? value = 0;
}
如果解析成功,value就是解析后的值,否則仍然為0。
轉(zhuǎn)載于:https://www.cnblogs.com/jguangliang/articles/1344672.html
總結(jié)
- 上一篇: [转]仿163网盘无刷新文件上传系统
- 下一篇: 向贝多芬靠近。