Similar topic
<div id="wrap" class=' @(ViewContext.RouteData.Values["iframe"] == 1 ? /*do sth*/ : /*do sth else*/')> </div>
EDIT 01-10-2014: Since this question is so popular, this answer has been improved.
In the above example, only values from RouteData , that is, only from RouteData strings that are intercepted by any registered route. To get the value of the query string, you must go to the current HttpRequest . The fastest way is to call (as TruMan pointed out) "Request.Querystring", so the answer should be:
<div id="wrap" class=' @(Request.QueryString["iframe"] == 1 ? /*do sth*/ : /*do sth else*/')> </div>
Can you also check RouteValues against QueryString MVC?
EDIT 05-05-2019: The above solution works for the .NET Framework.
As others noted, if you want to get the value of a query string in .NET Core, you should use the Query object from the Context.Request path. So it would be:
<div id="wrap" class=' @(Context.Request.Query["iframe"] == new StringValues("1") ? /*do sth*/ : /*do sth else*/')> </div>
Note that I use StringValues("1") in the expression because Query returns a StringValues object instead of a pure string . This clears the path for this script that I found.
Mariusz Jun 28 2018-12-12T00: 00Z
source share