Alternative to using Webclient to get HTML output

442 Views Asked by At

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?

1

There are 1 best solutions below

0
Darin Dimitrov On

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.