如何从URL获取数据

Vai*_*ain 2 .net c# asp.net url

我有一个URL http://localhost/TradeCredits/UnderWriter/EditQuote.aspx?QOT_ID = 1我想从URL获取QOT_ID.请建议如何做到这一点.

Amr*_*mry 5

您可以使用以下代码行:

int id = Convert.ToInt32(Request.QueryString["QOT_ID"]);
Run Code Online (Sandbox Code Playgroud)

或者如果你想进行适当的检查:

int id;
if (int.TryParse(Request.QueryString["QOT_ID"], out id)) {
    // Do something with the id variable
} else {
    // Do something when QOT_ID cannot be parsed into an int
}
Run Code Online (Sandbox Code Playgroud)