0

I am busy with trying to greet a person in the email, this email body is made from an html script but the issue i am having is that it prints out the variable name instead of the value itself. Here is my controller:

public async Task<IHttpActionResult> EmailReport([FromUri] ReportRequestViewModel request)
    {
      

        var reportEmailViewModel = new ReportEmailViewModel();

        reportEmailViewModel.Name = CurrentUser.Name;
        reportEmailViewModel.ScorecardName = _BEEScorecardService.GetById(request.ScorecardId).Name;
       


        var pdf = GetFileAsResponseMessage(docStream.ToArray(), report.FileName, true);

        var encoding = new System.Text.UTF8Encoding();
        var newReportEmail = new ReportEmailModel()
        {
           
            ToRecieverEmailAddress = CurrentUser.Email,
            Body = (System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("/Views/EmailTemplate/")+ "ReportEmail.cshtml", encoding)),
            attachment = pdf
        };
        _EmailService.SendReportEmail(newReportEmail);
        
        return Ok();
       
    }

My viewmodel for the persons name and other details:

    public class ReportEmailViewModel
{
    public string Name { get; set; }
    public string ScorecardName { get; set; }
}

and my chtml(I cut out some of the html to show exactly where the error is occuring):

@model BEE123.Web.UI.ViewModel.ReportEmailViewModel
<!DOCTYPE html>
<html>
<body>
    <div align='center'>
        <table class='MsoNormalTable' style='width:462.0pt;mso-cellspacing:1.5pt;mso-yfti-tbllook:1184' width='616'
               cellspacing='3' cellpadding='0' border='0'>
            <tbody>
                <tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes'>
                    <td style='padding:.75pt .75pt .75pt .75pt'>
                        <p class='MsoNormal'>
                            <span style='font-size:8.5pt;font-family:&quot;Segoe UI&quot;,sans-serif;mso-fareast-font-family:&quot;Times New Roman&quot;'>
                                <img id='_x0000_i1025'
                                     src='http://app.bee123.co.za/Images/BEE123EmailBanner.PNG' ?=''>
                                
                            </span>
                        </p>
                        <h1>
                            <span style='font-family:&quot;Segoe UI&quot;,sans-serif;mso-fareast-font-family:&quot;Times New Roman&quot;;color:#B8995F'>Scorecard Report</span>
                        </h1>
                        <p>
                            <span style='font-size:8.5pt;font-family:&quot;Segoe UI&quot;,sans-serif'>
                                Hi @Model.Name
                            </span>
                           
                        </p>

But this is what shows in the email: enter image description here

Mohammed Ismail
  • 196
  • 1
  • 15
  • Does this answer your question? [Return View as String in .NET Core](https://stackoverflow.com/questions/40912375/return-view-as-string-in-net-core) – Johnathan Barclay Jun 23 '20 at 09:59
  • @JohnathanBarclay So mine is a bit different because my controller is for an api endpoint which is used in my frontend for knockoutjs – Mohammed Ismail Jun 23 '20 at 10:03
  • You are currently reading the .cshtml file as plain text. The above answer shows how to parse a .cshtml file with a model using the view engine. – Johnathan Barclay Jun 23 '20 at 10:16

0 Answers0