While stepping through the generation of a View. Is there a way to see the HTML that has been generated to that point? I've tried looking through the locals variable list, but am having trouble finding it.
Asked
Active
Viewed 621 times
3
-
1As an alternative you could render a view to a string and view that way. Refer to http://stackoverflow.com/questions/483091/render-a-view-as-a-string – m0s Jul 15 '12 at 05:08
-
While I don't think this will solve the particular issue I was hoping for. I do have a place I can use that so thanks for the link! – Jared Jul 15 '12 at 22:11
-
@jared i think you should try to use PartailView because return type on partial view MvcHtmlString so can get all generated Html at server side for more info please refer http://craftycodeblog.com/2010/05/15/asp-net-mvc-render-partial-view-to-string/ – Shivkumar Oct 20 '12 at 07:01
-
@Shivkumar Partial views are good for bits of HTML that you want to reuse. I don't think that converting all of my documents to partials is a good practice (for the sake of solving this problem). Partials are good for reuse if it's not going to be reused then (in my opinion) it doesn't belong in a partial. – Jared Nov 27 '12 at 04:46
1 Answers
3
You can look at the ViewContext.Writer. Try adding...
((System.Web.Mvc.WebViewPage)(this)).ViewContext.Writer
to your watch window.

Aleksander Blomskøld
- 18,374
- 9
- 76
- 82

DaveMorganTexas
- 847
- 10
- 13
-
This will allow you to see the HTML that has been generated up to any point while stepping through your view. Have you tried it? Any concerns with this answer? – DaveMorganTexas Nov 28 '12 at 03:31
-
1While this code didn't work as written for me it clued me in to the solution so thanks for that. I ended up adding a watch for `(this).ViewContext.Writer.ToString()` For whatever reason when I included the cast there was a DLL conflict. At the bottom of my layout I included a `@if (false){}` so that I could grab the html in totality before it was returned (and obviously a break-point could be added sooner if you wanted to step through). – Jared Jan 06 '13 at 18:25