How to add media type to stylesheet reference asp

2019-07-21 09:26发布

问题:

I'm using asp mvc, and I'm using the following code to generate the CSS html reference:

@Styles.Render("~/Content/css")

which generates the following html:

<link href="/Content/site.css" rel="stylesheet"/>

and that works fine. However, I need to add media type as an additional attribute. How can I go about using this style.render to add attributes to the generated html? Should I be thinking about making the change in the bundle config instead?

edit: I would like the end product to look like this:

<link href="/Content/site.css" rel="stylesheet" media="handheld"/>

回答1:

You should be using @Styles.RenderFormat() for that:

@Styles.RenderFormat(@"<link href=""{0}""
                             rel=""stylesheet""
                             media=""handheld"" />",
                      "~/Content/css")


回答2:

Try this

< link href="@Styles.Url("~/Content/css")" rel="stylesheet" type="text/css" media="handheld" />