设置 'cshtml' 数据并返回一个字符串 [英] Set 'cshtml' data and return a string

查看:46
本文介绍了设置 'cshtml' 数据并返回一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个确认电子邮件模板 .cshtml 如下:

I have a confirmation email template .cshtml as following:

<html> 
    <head>
        <title>company name: Email Verification - Action Required</title> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head> 
    <body> 
            Thanks for signing up for company name!
            <br/>
            <br/>

            Thank you for signing up to company name. Please press the link below to confirm your email address <br/>
            If you did not sign up for company name, please ignore this email, and accept our apologies for the inconvenience.

            <br/>
            <br/>

            <a href="@Model.ConfirmLink">@Model.ConfirmLink</a>

            <br/>
            <br/>
            <br/>

            Thanks,<br/>
            The <a href="http://company name.com" >company name</a> Team                       
        </table>
    </body>
</html>

是否有一种机制可以设置数据 (@Model.ConfirmLink) 并以 string 形式返回结果?(不是手动替换字符串)

Is there a mechanism I can set data (@Model.ConfirmLink) and get back a result as string? (not manually replace string)

推荐答案

您可以使用 RazorEngine,它使用与 Razor 的语法相同,但使您能够在不需要 ASP.NET MVC 的情况下呈现文本.

You can use RazorEngine, which uses the same syntax as Razor does, but gives you the ability to render the text without the need of ASP.NET MVC.

您的代码将如何工作:

string template = yourHtmlCodeAsString;
string result = Razor.Parse(template, new { ConfirmLink = "http://.../" });

您可以从文件、资源等加载该模板字符串.

You can load that template string from a file, a resource, etc.

这篇关于设置 'cshtml' 数据并返回一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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