Removes area routing for local surface controllers and BeginUmbracoForm, adds strongly typed Html.Action<T>
method for rendering SurfaceController child actions regardless of area (so you don't have to specify). All relates to #U4-1727
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
using System.Web.Routing;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Dynamics;
|
||||
using Umbraco.Web.Mvc;
|
||||
@@ -83,6 +84,48 @@ namespace Umbraco.Web
|
||||
return filteredHtmlHelper.ValidationSummary(excludePropertyErrors, message, htmlAttributes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the result of a child action of a strongly typed SurfaceController
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="htmlHelper"></param>
|
||||
/// <param name="actionName"></param>
|
||||
/// <returns></returns>
|
||||
public static IHtmlString Action<T>(this HtmlHelper htmlHelper, string actionName)
|
||||
where T : SurfaceController
|
||||
{
|
||||
return htmlHelper.Action(actionName, typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the result of a child action of a SurfaceController
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="htmlHelper"></param>
|
||||
/// <param name="actionName"></param>
|
||||
/// <param name="surfaceType"></param>
|
||||
/// <returns></returns>
|
||||
public static IHtmlString Action(this HtmlHelper htmlHelper, string actionName, Type surfaceType)
|
||||
{
|
||||
Mandate.ParameterNotNull(surfaceType, "surfaceType");
|
||||
Mandate.ParameterNotNullOrEmpty(actionName, "actionName");
|
||||
|
||||
var routeVals = new RouteValueDictionary(new {area = ""});
|
||||
|
||||
var surfaceController = SurfaceControllerResolver.Current.RegisteredSurfaceControllers
|
||||
.SingleOrDefault(x => x == surfaceType);
|
||||
if (surfaceController == null)
|
||||
throw new InvalidOperationException("Could not find the surface controller of type " + surfaceType.FullName);
|
||||
var metaData = PluginController.GetMetadata(surfaceController);
|
||||
if (!metaData.AreaName.IsNullOrWhiteSpace())
|
||||
{
|
||||
//set the area to the plugin area
|
||||
routeVals.Add("area", metaData.AreaName);
|
||||
}
|
||||
|
||||
return htmlHelper.Action(actionName, metaData.ControllerName, routeVals);
|
||||
}
|
||||
|
||||
#region BeginUmbracoForm
|
||||
|
||||
/// <summary>
|
||||
@@ -307,7 +350,7 @@ namespace Umbraco.Web
|
||||
Mandate.ParameterNotNullOrEmpty(action, "action");
|
||||
Mandate.ParameterNotNull(surfaceType, "surfaceType");
|
||||
|
||||
var area = Umbraco.Core.Configuration.GlobalSettings.UmbracoMvcArea;
|
||||
var area = "";
|
||||
|
||||
var surfaceController = SurfaceControllerResolver.Current.RegisteredSurfaceControllers
|
||||
.SingleOrDefault(x => x == surfaceType);
|
||||
@@ -366,7 +409,6 @@ namespace Umbraco.Web
|
||||
object additionalRouteVals,
|
||||
IDictionary<string, object> htmlAttributes)
|
||||
{
|
||||
Mandate.ParameterNotNullOrEmpty(area, "area");
|
||||
Mandate.ParameterNotNullOrEmpty(action, "action");
|
||||
Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName");
|
||||
|
||||
|
||||
@@ -176,8 +176,6 @@ namespace Umbraco.Web.Mvc
|
||||
/// <param name="routeDefinition">The original route definition that would normally be used to route if it were not a POST</param>
|
||||
private IHttpHandler HandlePostedValues(RequestContext requestContext, PostedDataProxyInfo postedInfo, RouteDefinition routeDefinition)
|
||||
{
|
||||
var standardArea = Umbraco.Core.Configuration.GlobalSettings.UmbracoMvcArea;
|
||||
|
||||
//set the standard route values/tokens
|
||||
requestContext.RouteData.Values["controller"] = postedInfo.ControllerName;
|
||||
requestContext.RouteData.Values["action"] = postedInfo.ActionName;
|
||||
@@ -185,7 +183,7 @@ namespace Umbraco.Web.Mvc
|
||||
IHttpHandler handler = new MvcHandler(requestContext);
|
||||
|
||||
//ensure the controllerType is set if found, meaning it is a plugin, not locally declared
|
||||
if (!postedInfo.Area.InvariantEquals(standardArea))
|
||||
if (!postedInfo.Area.IsNullOrWhiteSpace())
|
||||
{
|
||||
//requestContext.RouteData.Values["controllerType"] = postedInfo.ControllerType;
|
||||
//find the other data tokens for this route and merge... things like Namespace will be included here
|
||||
|
||||
Reference in New Issue
Block a user