Feature request: RenderAsHtml as a generator option

Mar 25, 2013 at 11:29 AM
Edited Mar 25, 2013 at 11:30 AM
It would be useful to be able to render a view (or rather a webpages page) to a static html file within Visual Studio. Perhaps a little bit out of scope for the razor generator, but all the necessary pieces seem to be here so it would be a small thing to add I guess?

Sample uses :

split parts of a single page application cross .cshtml files and render them to one .html

create helpers for common html components (for example @Html.BootstrapSomeFormElement(...)) and render to html
Coordinator
Mar 25, 2013 at 5:24 PM
Not sure I'm following you. In order to do any kind of rendering in the context of an MVC app, you need the runtime MVC context (routing, ...). How could this rendering be done at design time?
Mar 25, 2013 at 6:03 PM
Edited Mar 25, 2013 at 6:39 PM
Yes

I create apps where only static files is hosted on my own site (and I'm using other services, dropbox, azure mobile services et c for data).

However when an app becomes big enough it would be nice to be able to separate the markup in different files, for example different client side views or components, and the markup from the server point of view is still static. The dynamic parts comes to play at client side (mvvm).

Also - instead of repeating the same markup again and again (for example for bootstrap controls) I use Razor helpers.

I use dynamically loaded templates but that requires multiple server calls plus I really like the Razor syntax to build my markup.

Here's an idea of what I like to write in my spa razor files:

index.cshtml:
<script type="sometemplating" id="templateOne">
@RenderPage("templateOne")
</script>
<script type="sometemplating" id="templateTwo">
@RenderPage("templateTwo")
</script>
<div id="container"></div>
templateOne.cshtml:
@Html.StylishForm(<text>
 @Html.LabelInput("foo","bar")
 @Html.LabelInput("something,"else")
</text>)
Hope it makes sense.

(I can achieve what I want by rendering my main razor in the browser and save the rendered markup.)