如何内嵌包括CSS样式的Razor视图? [英] How to include CSS styles inline in Razor view?

查看:842
本文介绍了如何内嵌包括CSS样式的Razor视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用邮政来渲染MVC剃刀意见和通过电子邮件发送。我有我已为电子邮件意见明确定义的自定义CSS。目前,我包括他们如下:

I am using Postal to render MVC Razor views and send them via email. I have a custom CSS that I have defined specifically for the email views. Currently I am including them as follows:

@Styles.Render("~/Content/EmailStyles.css")

不过,这仅包括相对链接的样式表,从而不会在一封电子邮件中工作:

However, this only includes the relative link to the stylesheet, which will not work in an email:

<link href="/Content/EmailStyles.css" rel="stylesheet"/>

我想包括样式表内联,以便它在电子邮件中正常运转。什么是呈现一个MVC视图中的基于文件的资源的内容的最佳方式?

I want to include the stylesheet inline so that it functions properly in the email. What is the best way to render the contents of a file-based resource within an MVC view?

推荐答案

我猜你会需要有一个自定义的帮手。在我的头顶上,有没有这样的渲染,包括该网站的绝对路径的CSS路径的方法。

I guess you will need to have a custom helper for that. On top of my head, there is no such a method to render the css path including the absolute path of the website.

例如。 HTTP:www.example.com/css/EmailStyles.css

e.g. http:www.example.com/css/EmailStyles.css

这篇关于如何内嵌包括CSS样式的Razor视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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