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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user