Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Parameters from URL

I been googling to find a way to read parameter value from URL but no success. In ASP.NET Webform we used to do Request.Querystring["name"] to get the value. How to do this in MVC3?

I need to access parameter in HtmlHelper class. Anyone please.

There is no clear answer on the internet for this. Strange...

like image 631
Pirzada Avatar asked May 29 '11 23:05

Pirzada


1 Answers

I still use HttpContext.Current.Request.QueryString in MVC3...

if (!Request.QueryString["ParameterName"].IsEmpty())
{
  // Do something only if URL parameter "ParameterName" is not empty...
}

For example:

http://192.168.1.106:7777/Measurement?sort=FatPercentage&sortdir=DESC

if (!Request.QueryString["sort"].IsEmpty())
{
  // sort=FatPercentage. It's not empty and this code block will be executed
}
like image 109
Leniel Maccaferri Avatar answered Sep 28 '22 19:09

Leniel Maccaferri