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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With