如何将媒体类型添加到样式表参考ASP MVC [英] How to add media type to stylesheet reference asp mvc

查看:58
本文介绍了如何将媒体类型添加到样式表参考ASP MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp mvc,并且正在使用以下代码来生成CSS html参考:

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

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

它将生成以下html:

which generates the following html:

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

,效果很好.但是,我需要添加媒体类型作为附加属性.如何使用此style.render向生成的html添加属性?我是否应该考虑在bundle config中进行更改?

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

推荐答案

您应该为此使用 @ Styles.RenderFormat():

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

这篇关于如何将媒体类型添加到样式表参考ASP MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆