如何在ASP.NET MVC 2项目的编程设置样式表? [英] How to set stylesheet programmatically in an ASP.NET MVC 2 project?

查看:185
本文介绍了如何在ASP.NET MVC 2项目的编程设置样式表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以..这是我的Site.Master ASPX文件在MVC2项目上半部分:

So.. this is the upper part of my site.master ASPX file in an MVC2 project:

<head runat="server">
   <link href="<%= ViewData[SomeNamespace.StyleSheetKey]; %>" rel="stylesheet" type="text/css" />
</head>
<div foo="<%= (string) ViewData[SomeNamespace.StyleSheetKey] %>">bar</div>

现在div标签呈现样式名称正确,但因为它是写一个在链接标签被渲染,而不间preTED。另外的路径preFIX加入。

Now the div tag renders the stylesheet name properly, but the one in the link-tag is rendered as it is written, without being interpreted. In addition a path prefix is added.

因此​​,ASP.NET引擎似乎想用在link标签的href-参数文本麻烦,帮我$ ​​P $ PFIX我的.css文件用正确的相对路径。

So the ASP.NET engine seems to want to hassle with the text in the href- argument in the link tag, "helping" me to prefix my .css file with the correct relative path.

如何将现在能够以编程设定的样式表的名称?

How will I now be able to set the name of the style sheet programmatically?

推荐答案

好吧,尝试删除=服务器,从标签中的&LT; HEAD&GT; 标记

Ok, Try removing the runat="server" tag from the <head> tag

这篇关于如何在ASP.NET MVC 2项目的编程设置样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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