Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
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
      }


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
Posted
Updated 18-Apr-16 21:22pm
Comments
Richard MacCutchan 18-Apr-16 9:18am    
Do not use var for all your variable types. It makes it much more difficult to figure out what you intend by each statement. Also you cannot convert random objects of one type to objects of another.
Sergey Alexandrovich Kryukov 18-Apr-16 9:45am    
And what kind of help would you expect? Aren't the error messages obvious? What makes you trying to convert the type you cannot convert? If you don't understand some basics, "fixing" your bugs won't help you. You need to learn basics first.
—SA

1 solution

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" is a string, but you have to provide a System.IO.TextWriter for that parameter.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900