From 05bdd42567444f22afcb84aaa36d4e785a481f3e Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Fri, 28 Sep 2012 08:08:36 +0700 Subject: [PATCH] Fixes issue with UmbracoHelper in back office when there is not Document. Adds another overload to BeginUmbracoForm. --- src/Umbraco.Web/HtmlHelperRenderExtensions.cs | 13 +++++++++++++ src/Umbraco.Web/Umbraco.Web.csproj | 1 + src/Umbraco.Web/UmbracoContext.cs | 6 +++--- src/Umbraco.Web/UmbracoHelper.cs | 10 +++++++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs index f353a07214..865b0920b0 100644 --- a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs @@ -306,6 +306,19 @@ namespace Umbraco.Web return html.BeginUmbracoForm(action, typeof(T), additionalRouteVals, htmlAttributes); } + /// + /// Helper method to create a new form to execute in the Umbraco request pipeline to a surface controller plugin + /// + /// + /// + /// + /// + /// + public static MvcForm BeginUmbracoForm(this HtmlHelper html, string action, string controllerName, string area) + { + return html.BeginUmbracoForm(action, controllerName, area, null, new Dictionary()); + } + /// /// Helper method to create a new form to execute in the Umbraco request pipeline to a surface controller plugin /// diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 3f0f7bc65d..373a51f3cf 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -311,6 +311,7 @@ editView.aspx + ASPXCodeBehind diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 916daddc1c..556ed045f1 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -245,7 +245,7 @@ namespace Umbraco.Web /// /// Gets the current page ID, or null if no page ID is available (e.g. a custom page). /// - public virtual int? PageId + public int? PageId { get { @@ -265,7 +265,7 @@ namespace Umbraco.Web /// Gets the current logged in Umbraco user (editor). /// /// The Umbraco user object or null - public virtual User UmbracoUser + public User UmbracoUser { get { @@ -277,7 +277,7 @@ namespace Umbraco.Web /// /// Determines whether the current user is in a preview mode and browsing the site (ie. not in the admin UI) /// - public virtual bool InPreviewMode + public bool InPreviewMode { get { diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index 3ba60902ca..7d96407157 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -37,8 +37,12 @@ namespace Umbraco.Web internal UmbracoHelper(UmbracoContext umbracoContext) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); + if (umbracoContext.RoutingContext == null) throw new NullReferenceException("The RoutingContext on the UmbracoContext cannot be null"); _umbracoContext = umbracoContext; - _currentPage = _umbracoContext.DocumentRequest.Document; + if (_umbracoContext.IsFrontEndUmbracoRequest) + { + _currentPage = _umbracoContext.DocumentRequest.Document; + } } @@ -130,6 +134,10 @@ namespace Umbraco.Web RenderFieldEncodingType encoding = RenderFieldEncodingType.Unchanged, string formatString = "") { + if (_currentPage == null) + { + throw new InvalidOperationException("Cannot call this method when not rendering a front-end document"); + } return Field(_currentPage, fieldAlias, valueAlias, altFieldAlias, altValueAlias, altText, insertBefore, insertAfter, recursive, convertLineBreaks, removeParagraphTags, casing, encoding, formatString);