I want to send an email in MVC 5 application. I have the email body store in a file called _EmailBody.cshtml
I am following the similar approach described here Render a view as a string
and I have my setup like this
public static string RenderRazorViewToString(this Controller controller, string viewName, object model)
    {
        controller.ViewData.Model = model;
        using (var sw = new StringWriter())
        {
            var viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
            // viewName is "~/Views/Applications/Emails/_EmailBody.cshtml" 
            // blah blah blah
            return "....";
        }
    }
The error happens in this line
var viewResult = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName);
and the error is
object reference not set to an instance of an object
Do you have any idea what is causing the problem?
Thank you
 
    