0

A product I've inherited is using WebClient to read HTML from a MVC based site. Each page is a different type of e-mail, so in order to compose and send an e-mail they use WebClient to request a URL and download the string.

            var outputHtml = string.Empty; 
            using (WebClient client = new WebClient())
            {
                client.Encoding = Encoding.UTF8;
                outputHtml = client.DownloadString(emailURL);
            }
            return outputHtml;

Is there a way to remove the need to host this email based site but retain most of this code. I guess what I need to do is pass my request to the controller and retrieve the output after the razor engine has passed the view model through the cshtml page.

Is that possible?

P456678
  • 175
  • 1
  • 2
  • 10

1 Answers1

0

There are many ways you could render a Razor view to a string. One possibility is to use RazorEngine. Another possibility is to use some specifically designed framework for this purpose such as Postal.

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928