2011-03-03 32 views
1

结合考虑下面的代码片段在一个视图:CSS - 错误时,代码

<style type="text/css"> 
input[type=text] { 
    width: <%: Model.CmsConfiguration.cms_form_width %>px; 
} 
</style> 

现在,至今工作。但是视觉工作室现在在这个视图中显示了一个令人讨厌的错误,如Validation (CSS 2.1): '<%:' is not a valid value for the 'width' property.。有没有办法摆脱这个?

THX任何的窍门 sl3dg3

回答

2

尝试更换<%:<%=

<style type="text/css"> 
    input[type=text] 
    { 
    width: <%= Model.CmsConfiguration.cms_form_width %>px; 
    } 
</style> 

作品以及

1

你可能最好使用Generic Handler,只要你想产生的动态CSS。

看一看这里:

http://www.brainbell.com/tutorials/ASP/Generic_Handlers_%28ASHX_Files%29.html

处理程序产生select这是不是一个好主意,但是有它产生的CSS似乎是做一个完全有效的事情。这个例子仅仅是为了演示Generic Handler的使用。

下面是一些可能做什么你是后:

using System.Web; 
public class CustomFormHandler : IHttpHandler { 

    public void ProcessRequest (HttpContext context) { 

     context.Response.ContentType = "text/css"; 
     context.Response.Write("input[type=text] { "}; 
     context.Response.Write(" width: " + Model.CmsConfiguration.cms_form_width + "px;"); 
     context.Response.Write("}"}; 
    } 

    public bool IsReusable { 
     get { 
      return false; 
     } 
    } 
} 
+0

看起来很有趣 - 但在我的小范围内可能会有一点点开销? – sl3dg3