Files
Umbraco-CMS/src/Umbraco.Web/Mvc/RenderActionInvoker.cs
2012-08-07 21:40:34 +06:00

35 lines
1.2 KiB
C#

using System.Web.Mvc;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// Ensures that if an action for the Template name is not explicitly defined by a user, that the 'Index' action will execute
/// </summary>
public class RenderActionInvoker : ControllerActionInvoker
{
/// <summary>
/// Ensures that if an action for the Template name is not explicitly defined by a user, that the 'Index' action will execute
/// </summary>
/// <param name="controllerContext"></param>
/// <param name="controllerDescriptor"></param>
/// <param name="actionName"></param>
/// <returns></returns>
protected override ActionDescriptor FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, string actionName)
{
var ad = base.FindAction(controllerContext, controllerDescriptor, actionName);
//now we need to check if it exists, if not we need to return the Index by default
if (ad == null)
{
//check if the controller is an instance of RenderMvcController
if (controllerContext.Controller is RenderMvcController)
{
return new ReflectedActionDescriptor(controllerContext.Controller.GetType().GetMethod("Index"), "Index", controllerDescriptor);
}
}
return ad;
}
}
}