0

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)
                {
                    page.Controls.Add(item);
                }

                HttpContext.Current.Server.Execute(page, xhtmltextwriter, false);
            }

Thanks, Jim

Marcin Deptuła
  • 11,789
  • 2
  • 33
  • 41
JBaltika
  • 1
  • 2

2 Answers2

0

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.

Marcin Deptuła
  • 11,789
  • 2
  • 33
  • 41
0

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).

Andrew Stanton-Nurse
  • 6,274
  • 1
  • 28
  • 20