This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RazorHelpers | |
| { | |
| // This approach is using WebPages, where there is no concept of a Controller | |
| public static string RenderTemplate(string template, object model) | |
| { | |
| var page = WebPageBase.CreateInstanceFromVirtualPath("~/templates/" + template + ".cshtml"); | |
| var context = new WebPageContext(new HttpContextWrapper(HttpContext.Current), page, null); | |
| var htmlWriter = new StringWriter(); | |
| // Access your model through PageData["Model"] in the view | |
| context.PageData["Model"] = model; |