From 8be97295dc00982ef12d49b33ca6fa73c9443bf3 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Fri, 16 Nov 2012 00:38:03 +0500 Subject: [PATCH] Added new method to RenderMvcController for easier return of the current template when hijacking routes. Added better error checking for media handling in MVC. --- src/Umbraco.Web/DefaultPublishedMediaStore.cs | 14 ++++++++++++++ src/Umbraco.Web/Mvc/RenderMvcController.cs | 19 ++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web/DefaultPublishedMediaStore.cs b/src/Umbraco.Web/DefaultPublishedMediaStore.cs index 79eed8ef72..4b0909936f 100644 --- a/src/Umbraco.Web/DefaultPublishedMediaStore.cs +++ b/src/Umbraco.Web/DefaultPublishedMediaStore.cs @@ -125,6 +125,20 @@ namespace Umbraco.Web if (media != null && media.Current != null) { media.MoveNext(); + var moved = media.Current.MoveToFirstChild(); + //first check if we have an error + if (moved) + { + if (media.Current.Name.InvariantEquals("error")) + { + return null; + } + } + if (moved) + { + //move back to the parent and return + media.Current.MoveToParent(); + } return ConvertFromXPathNavigator(media.Current); } diff --git a/src/Umbraco.Web/Mvc/RenderMvcController.cs b/src/Umbraco.Web/Mvc/RenderMvcController.cs index 08469ef9ff..9a7d0a4f64 100644 --- a/src/Umbraco.Web/Mvc/RenderMvcController.cs +++ b/src/Umbraco.Web/Mvc/RenderMvcController.cs @@ -61,20 +61,33 @@ namespace Umbraco.Web.Mvc } /// - /// The default action to render the front-end view + /// Returns an ActionResult based on the template name found in the route values and the given model. /// + /// /// /// - public virtual ActionResult Index(RenderModel model) + /// + /// If the template found in the route values doesn't physically exist, then an empty ContentResult will be returned. + /// + protected ActionResult CurrentTemplate(T model) { var template = ControllerContext.RouteData.Values["action"].ToString(); if (!EnsurePhsyicalViewExists(template)) { return Content(""); } - return View(template, model); } + /// + /// The default action to render the front-end view + /// + /// + /// + public virtual ActionResult Index(RenderModel model) + { + return CurrentTemplate(model); + } + } } \ No newline at end of file