How to get query string parameter from MVC Razor markup?

后端 未结 6 1073
情歌与酒
情歌与酒 2020-12-13 22:58

I want to check the URL parameter in my Razor markup. For example, how do I do something like this:

6条回答
  •  醉梦人生
    2020-12-13 23:44

    I think a more elegant solution is to use the controller and the ViewData dictionary:

    //Controller:
    public ActionResult Action(int IFRAME)
        {
            ViewData["IsIframe"] = IFRAME == 1;
            return View();
        }
    
    //view
    @{
        string classToUse = (bool)ViewData["IsIframe"] ? "iframe-page" : "";
       
    }

提交回复
热议问题