From cec4d41df7b20de321e22a06e2d26255ee91bca8 Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 4 Mar 2014 11:58:37 +0100 Subject: [PATCH] Add comments to UmbracoViewPageOfTModel --- src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs index 373e103a56..b7220b7cc1 100644 --- a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs +++ b/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs @@ -141,6 +141,7 @@ namespace Umbraco.Web.Mvc // maps model protected override void SetViewData(ViewDataDictionary viewData) { + // if view data contains no model, nothing to do var source = viewData.Model; if (source == null) { @@ -148,6 +149,8 @@ namespace Umbraco.Web.Mvc return; } + // get the type of the view data model (what we have) + // get the type of this view model (what we want) var sourceType = source.GetType(); var targetType = typeof (TModel); @@ -160,13 +163,15 @@ namespace Umbraco.Web.Mvc // try to grab the content // if no content is found, return, nothing we can do - var sourceContent = source as IPublishedContent; + var sourceContent = source as IPublishedContent; // check if what we have is an IPublishedContent if (sourceContent == null && sourceType.Implements()) { + // else check if it's an IRenderModel => get the content sourceContent = ((IRenderModel)source).Content; } if (sourceContent == null) { + // else check if we can convert it to a content var attempt = source.TryConvertTo(); if (attempt.Success) sourceContent = attempt.Result; }