2
I have a URL where it returns an HTTP QueryString
, and I need to retrieve the information from the URL and convert it into variables to make queries in the database.
In PHP just use the $_GET[""]
, now in C# I don’t know how to proceed.
Let me give you an example to clarify.
I have the URL: http://html.net/page.php?name=Joe&age=12
I have to take the values "Joe" and "12" for a later consultation.
Do not forget to check that the parameter is null before using and do not use sensitive parameters in the query string. Ex: login, password, logged in user id, Session, any control parameter that can be used to take over a session without necessarily knowing any login.
– Intruso
I added this code to my controller, but when calling the page, the null variable.
– Randrade
public Actionresult Dependent() { string name = Request.Querystring["name"]; var dependent = dependentRepository.Dependentes.Where(r => r.Nmpessoa == name). Tolist(); Return View(dependent); } And am I trying to recover the value of this URL: http://localhost/User/Dependent? name=Joao
– Randrade
It worked, I forgot to put the parameters in my controller. Thank you all.
– Randrade
I have to put the amount of parameters I will receive in my Query String in my controller, correct?
– Randrade