How to add media type to stylesheet reference asp

2019-07-21 09:35发布

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"/>

2条回答
霸刀☆藐视天下
2楼-- · 2019-07-21 09:44

Try this

< link href="@Styles.Url("~/Content/css")" rel="stylesheet" type="text/css" media="handheld" />
查看更多
对你真心纯属浪费
3楼-- · 2019-07-21 10:02

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

@Styles.RenderFormat(@"<link href=""{0}""
                             rel=""stylesheet""
                             media=""handheld"" />",
                      "~/Content/css")
查看更多
登录 后发表回答