ASP.NET MVC - Rendering and sending output thought webservice
Does anyone knows the way to parse .cshtml layout file and render output as string in webservice? Any tips ?
In ASP.NET C# something like this XhtmlTextWriter xhtmltextwriter = new XhtmlTextWriter(stringwriter);
// Create a new Page and add the control to it.
using (Page page = new Page())
{
foreach (Control item in controls)
{
开发者_如何学Go page.Controls.Add(item);
}
HttpContext.Current.Server.Execute(page, xhtmltextwriter, false);
}
Thanks, Jim
You can check newest Phil Haack's blog post here. He explains how to use Razor engine to parse *.cshtml files. From this you can use it everywhere, fe. send it through web service.
You can definitely host the Razor engine in a Web Service. I wrote a blog post about it here: http://anur.se/razorhost. If you want something simpler, I'd suggest using Razor Engine, which abstracts away the complex stuff and provides simple facades like Razor.Parse(template, model)
.
精彩评论