Skip to content
Kam Figy edited this page May 30, 2013 · 1 revision

Rendering Diagnostics

All types of Views (Razor, WebControl, UserControl) automatically emit helpful debug information.

When compiled in debug mode (<compilation debug="true"> in web.config), all views will emit in HTML comments:

  • The full path to the rendering (or namespace if a WebControl)
  • The timestamp when the rendering was rendered (will be in the past if the control was output cached)
  • A readout of any active output caching settings that were in effect at render time (i.e. cacheable, varybydata)
  • At the bottom of the rendering, the full path will be repeated along with a time in ms for the rendering to execute

Here's an example:

<!-- Begin Rendering ~/layouts/Sample Inner Sublayout.ascx -->
<!-- Rendering was output cached at 5/16/2013 9:31:42 PM, ClearOnIndexUpdate, VaryByData, VaryByQueryString -->
<h1>Hello, world!</h1>
<!-- End Rendering ~/layouts/Sample Inner Sublayout.ascx, render took 0ms -->

This is designed to make debugging output caching easier as well as reduce load on frontend folks when they cannot find a file to edit the markup.

Automatic View Hiding

Sometimes it may not be possible to convert a data source into a valid model item. For example, you might have a page editor rendering that has no data source set - or an item of the wrong template set. Or maybe your presenter cannot resolve data and returns null.

In this situation, when the model is null, Blade will automatically hide the rendering from the end user. However if you login to Preview or Page Editor modes, you will see a helpful message in its place designed to help you figure out why the rendering is not being shown to the end user:

Hidden View: ~/layout/test.cshtml

View was automatically hidden because its model type FakeModelClass could not be resolved. Possible causes:

  • The view's data source value, /sitecore/content/Home, may not point to valid item(s).
  • The presenter, MyPresenterClass, returned null for the model. This would usually indicate either the data source cannot be converted to the model type, or that no data exists to display.

This message is only displayed in preview or edit mode, and will not appear to end users.

You can extend this behavior if you don't like it by overriding the RenderWhenModelIsNull method of the view base classes.

Clone this wiki locally