I'm currently working with C# and I want to get the variable of a GET method. (like this: index.cshtml?id=thisvariable)
I'm currently using:
if (HttpContext.Current.Request.HttpMethod == "GET")
And it works, but I don't know how to get the variable.
In order to get data sent by a GET
request, you read the QueryString
from the Request
.
var id = HttpContext.Current.Request.QueryString["id"];
You should also add checks to make sure that the QueryString[KEY]
exists, so that you don't get a NullReferenceException
when it tries to find a KEY
that is not present.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.