I want to check the URL parameter in my Razor markup. For example, how do I do something like this:
<div id="wrap" class="@{if (URL "IFRAME" PARAMETER EQUALS 1) iframe-page}">
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Similar thread
EDIT 01-10-2014:
Since this question is so popular this answer has been improved.
The example above will only get the values from
RouteData, so only from the querystrings which are caught by some registered route. To get the querystring value you have to get to the currentHttpRequest. Fastest way is by calling (as TruMan pointed out) `Request.Querystring’ so the answer should be:You can also check RouteValues vs QueryString MVC?
EDIT 03-05-2019:
Above solution is working for .NET Framework.
As others pointed out if you would like to get query string value in .NET Core you have to use
Queryobject fromContext.Requestpath. So it would be:Please notice I am using
StringValues("1")in the statement becauseQueryreturnsStringValuesstruct instead of purestring. That’s cleanes way for this scenerio which I’ve found.