gpt4 book ai didi

html - 如何使用@RenderPage 内嵌 CSS 内容 - MVC Razor

转载 作者:太空狗 更新时间:2023-10-29 16:50:18 32 4
gpt4 key购买 nike

我目前正在将元素中的一个页面导出到 Excel,这将不允许链接外部内容,例如外部 CSS。

我想要实现的是一种在我的 View 中包含 CSS 文件但直接从 Visual Studio 自动缩小的 CSS 文件调用它的简单方法。

所以,在我看来我已经尝试过这个:

<style type="text/css">
@RenderPage("~/CSS/_ExportStyles.min.css")
</style>

但这样做会返回以下错误:

Server Error in '/' Application.

The following file could not be rendered because its extension ".css" might not be supported: "~/CSS/_ExportStyles.min.css".

我所知道的方法是将 CSS 放在普通的 .cshtml 文件中并包含它,但我会失去 ".min" 的能力保持文件较小并允许我自动删除评论等的文件。

最佳答案

所以,事实证明 @RenderPage 不是我要找的...

我需要的是:

@Html.Raw(File.ReadAllText(Server.MapPath("~/CSS/_ExportStyles.min.css")))

关于html - 如何使用@RenderPage 内嵌 CSS 内容 - MVC Razor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21427643/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com