CSS - 与代码结合时出错

发布于 2024-10-20 09:01:49 字数 357 浏览 1 评论 0原文

在视图中给出以下代码片段:

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

现在,到目前为止都有效。但 Visual Studio 现在在此视图中显示一个严重错误,例如 Validation (CSS 2.1): '<%:' is not a valid value for the 'width' property.。有办法摆脱这个吗?

感谢您的任何提示 SL3DG3

Given following snippet in a view:

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

Now, that works so far. But visual studio shows now a nasty error within this view like Validation (CSS 2.1): '<%:' is not a valid value for the 'width' property.. Is there a way to get rid of this?

Thx for any tipps
sl3dg3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦爱 2024-10-27 09:01:49

尝试将 <%: 替换为 <% =

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

效果很好

Try replacing <%: at <% =

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

works well

恰似旧人归 2024-10-27 09:01:49

您可能最好使用一个通用处理程序来生成您想要的动态CSS。

看看这里:

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

处理程序生成一个 select 这不是一个好主意,但让它生成 CSS 似乎是一件完全有效的事情。该示例只是为了演示通用处理程序的使用。

这可能会满足您的需求:

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;
        }
    }
}

You are probably better off using a Generic Handler that produces the dynamic CSS as you want.

Have a look here:

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

The handler produces a select which is not such a good idea, but to have it produce CSS seems like a perfectly valid thing to do. The example is merely to demonstrate the use of the Generic Handler.

Here is something that might do what you are after:

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;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文