Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用要呈现为html的RazorEngine插入html是填充模板_C#_Html_Razor - Fatal编程技术网

C# 使用要呈现为html的RazorEngine插入html是填充模板

C# 使用要呈现为html的RazorEngine插入html是填充模板,c#,html,razor,C#,Html,Razor,我在html模板中呈现html时遇到问题。我目前正在使用razorEngine来填充我们在电子邮件中使用的模板。我在呈现时遇到问题的信息是url。由于客户端的要求,我们不能在电子邮件中有可点击的链接,因此我必须将url作为普通字符串,电子邮件客户端的问题是,无论您是否将url字符串定义为链接,它们都会将url字符串呈现为链接。为了避免这种情况,我在整个链接中添加了两个零空间图像来打破它 这是填充模板的代码: Engine.Razor.Compile(content, "template"); E

我在html模板中呈现html时遇到问题。我目前正在使用razorEngine来填充我们在电子邮件中使用的模板。我在呈现时遇到问题的信息是url。由于客户端的要求,我们不能在电子邮件中有可点击的链接,因此我必须将url作为普通字符串,电子邮件客户端的问题是,无论您是否将url字符串定义为链接,它们都会将url字符串呈现为链接。为了避免这种情况,我在整个链接中添加了两个零空间图像来打破它

这是填充模板的代码:

Engine.Razor.Compile(content, "template");
Engine.Razor.Run("template", null, data)
传入的数据是作业对象:

{
    "Code": "235466",
    "FirstName": "First",
    "LastName": "Last",
    "URL": "<p>http<img src=\"\" width=\"0\" height=\"0\">s:<img src=\"\" width=\"0\" height=\"0\">//test.<img src=\"\" width=\"0\" height=\"0\">test.<img src=\"\" width=\"0\" height=\"0\">com/account/forgotpassword/</p>"
}
{
“代码”:“235466”,
“FirstName”:“First”,
“LastName”:“Last”,
“URL”:“https://test.test.com/account/forgotpassword/

” }
模板中的标记与模板匹配通常如下所示:

  • @Model.FirstName
  • @Model.LastName
  • @Model.LastName
除了我试图呈现为html的url之外:

  • @原始(Model.URL)
尝试输入值时引发以下错误:

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:与“RazorEngine.Templateing.TemplateBase.Raw(string)”匹配的最佳重载方法具有一些无效参数

如果要将URL直接放入Raw()中,它将正常工作:

@Raw("<p>http<img src="" width="0" height="0">s:<img src="" width="0" height="0">//test.<img src="" width="0" height="0">test.<img src="" width="0" height="0">com/account/forgotpassword/</p>")
@Raw(https://test.test.com/account/forgotpassword/

”)
有人能看到我在这里遗漏了什么吗?

对@Raw()的调用需要一个IceNodeString,而不是一个文本


模型。URL
不是字符串。它可能是一个
Newtonsoft.Json.Linq.JValue
。您需要首先使用以下命令将其转换为字符串:

@Raw(Model.URL.ToString())
只是要小心,确保Model.URL不是空的