ASP.NET MVC-将CSS添加到视图中(视图内部不是外部.css文件) [英] ASP.NET MVC - Adding CSS to your view (inside of the view not an external .css file)

查看:58
本文介绍了ASP.NET MVC-将CSS添加到视图中(视图内部不是外部.css文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ASP.NET MVC的新手.我想问问是否有一种方法可以在视图内添加CSS,但不使用外部.css文件?例如: table {border:5px solid red;} (就像您在普通的HTML-CSS项目中那样)?

I am new to ASP.NET MVCs. I want to ask if there is a way to add CSS inside your view, but not using an external .css file? For example: table {border: 5px solid red;} (Just like you would do it in a normal HTML-CSS project)?

推荐答案

考虑使用小节.在您的布局中添加:

Consider using sections. In your layout add:

<head>
    ...
    @RenderSection("Styles", required: false)
</head>

然后,在您看来:

@section Styles
{
    <style type="text/css">
        table { border: 5px solid red; }
    </style>
}

这将具有将样式标签添加到HTML的 head 中的效果,而不是在整个代码中乱扔 style 标签.

This will have the effect of adding this style tag into the head of your HTML where it should be, instead of littering style tags throughout your code.

这篇关于ASP.NET MVC-将CSS添加到视图中(视图内部不是外部.css文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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