错误:无法从'string'转换为'system.io.textwriter' [英] Error:cannot convert from 'string' to 'system.io.textwriter'
问题描述
public ActionResult TestEmailTemplate()
{
return View();
}
[HttpPost]
public ActionResult TestEmailTemplate(string fortest)
{
ParsingTemplate();
return View();
}
private void ParsingTemplate()
{
string templateFilePath = System.Web.HttpContext.Current.Server.MapPath("~/EmailTemplates/EmailTemplateTest.html");
var templateAsString = System.IO.File.ReadAllText(templateFilePath);
var myViewModel = new TestEmailTemplateViewModel
{
UserFullName = "Mohamed Nady",
UserName = "NADY",
SiteUrl = "http://www.mohnady.com",
RegDate = DateTime.Now.ToString()
};
var body = RazorEngine.Engine.Razor.RunCompile(templateAsString, "templateKey", typeof(TestEmailTemplateViewModel), myViewModel);
SendEmail("naadydev@gmail.com", "m.nady@najran.gov.sa", "testEmail", body);
}
private void SendEmail(string from, string to, string subject, string body)
{
// Sending .net Email Code
}
< b>我尝试了什么:
hi frnds,
i我在尝试Asp。 Net MVC Razor电子邮件模板..我已经给出了我的代码。我得到3个错误。
1.无法从'string'转换为'System.IO.TextWriter'
2.无法从'string'转换为'RazorEngine.Templating.ITemplateKey'
3.Error:最好的重载方法匹配'RazorEngine.Templating.IRazorEngineService.RunCompile(RazorEngine.Templat ing.ITemplateKey,System.IO.TextWriter,System.Type,object,RazorEngine.Templating.DynamicViewBag)'有一些无效的参数
并且,我正在获得Error This Line本身
var body = RazorEngine.Engine.Razor.RunCompile(templateAsString,templateKey,typeof(TestEmailTemplateViewModel),myViewModel);
请帮帮我这个
What I have tried:
hi frnds,
i am trying Asp.Net MVC Razor Email Template..i have give above my code.in that I am getting 3 Error.
1.cannot convert from 'string' to 'System.IO.TextWriter'
2. cannot convert from 'string' to 'RazorEngine.Templating.ITemplateKey'
3.Error:The best overloaded method match for 'RazorEngine.Templating.IRazorEngineService.RunCompile(RazorEngine.Templating.ITemplateKey, System.IO.TextWriter, System.Type, object, RazorEngine.Templating.DynamicViewBag)' has some invalid arguments
And,am getting Error This Line itself
var body = RazorEngine.Engine.Razor.RunCompile(templateAsString, "templateKey", typeof(TestEmailTemplateViewModel), myViewModel);
Please help me For this
推荐答案
比较这两个行:
Just compare these two lines:
RunCompile(RazorEngine.Templating.ITemplateKey, System.IO.TextWriter, System.Type, object, RazorEngine.Templating.DynamicViewBag)
RunCompile(templateAsString, "templateKey", typeof(TestEmailTemplateViewModel), myViewModel)
templateKey
是一个字符串,但是你必须为该参数提供 System.IO.TextWriter
。
"templateKey"
is a string, but you have to provide a System.IO.TextWriter
for that parameter.
这篇关于错误:无法从'string'转换为'system.io.textwriter'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!