Added new method to RenderMvcController for easier return of the current template when hijacking routes.

Added better error checking for media handling in MVC.
This commit is contained in:
Shannon Deminick
2012-11-16 00:38:03 +05:00
parent 3dd411f159
commit 8be97295dc
2 changed files with 30 additions and 3 deletions

View File

@@ -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);
}

View File

@@ -61,20 +61,33 @@ namespace Umbraco.Web.Mvc
}
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="model"></param>
/// <returns></returns>
public virtual ActionResult Index(RenderModel model)
/// <remarks>
/// If the template found in the route values doesn't physically exist, then an empty ContentResult will be returned.
/// </remarks>
protected ActionResult CurrentTemplate<T>(T model)
{
var template = ControllerContext.RouteData.Values["action"].ToString();
if (!EnsurePhsyicalViewExists(template))
{
return Content("");
}
return View(template, model);
}
/// <summary>
/// The default action to render the front-end view
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public virtual ActionResult Index(RenderModel model)
{
return CurrentTemplate(model);
}
}
}