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:
Shannon Deminick
2013-02-19 06:19:26 +06:00
parent 12f8638223
commit 005d3e7d64
2 changed files with 45 additions and 5 deletions

View File

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