0

I have a css file referenced in my _layout.cshtml

<link rel="stylesheet" type="text/css" href="//css/styles-640.css" />

there are 2 different versions (640 and 720) for displaying the page in different sizes

The size is a value in the querystring

How can I read the value from the querystring and dynamically inject it into the filename of the .css file?

This is in the master page (_layout.cshtml) and it obviously has lots of different ViewModels depending on which view is being rendered

2 Answers 2

2
@if(Request["size"] == 640) {
    <link rel="stylesheet" type="text/css" href="//css/styles-640.css" />
} else {
    <link rel="stylesheet" type="text/css" href="//css/styles-720.css" />
}
Sign up to request clarification or add additional context in comments.

2 Comments

VS Compiler reports me error: Error 1 Operator '==' cannot be applied to operands of type 'string' and 'int'
@misak in this case, "size" is being passed as a string, so compare as a string : @if(Request["size"] == "640") {.
0

It's very easy, Use condition @if in _layout.cshtml. Don't remember call cast function.

Request.QueryString["big"] and Request["big"] are same

@if (Request.QueryString["big"].AsBool()==true)
{
    <link rel="stylesheet" type="text/css" href="//css/styles-720.css" />

}
else
{
    <link rel="stylesheet" type="text/css" href="//css/styles-640.css" />
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.