From 1fa1d7df3e1029e8321890ff9ea2b5ec48065898 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Fri, 5 Jan 2018 11:27:54 -0800 Subject: [PATCH] Add missing `RenderPartial(...)` overload - #7127 - also remove some redundant `null` checks --- .../Rendering/HtmlHelperPartialExtensions.cs | 91 +++++-------------- .../HtmlHelperPartialExtensionsTest.cs | 1 + 2 files changed, 26 insertions(+), 66 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/HtmlHelperPartialExtensions.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/HtmlHelperPartialExtensions.cs index 8d9bdac59a..ff51c6cfd6 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/HtmlHelperPartialExtensions.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Rendering/HtmlHelperPartialExtensions.cs @@ -115,20 +115,8 @@ namespace Microsoft.AspNetCore.Mvc.Rendering /// This method synchronously calls and blocks on /// /// - public static IHtmlContent Partial( - this IHtmlHelper htmlHelper, - string partialViewName) + public static IHtmlContent Partial(this IHtmlHelper htmlHelper, string partialViewName) { - if (htmlHelper == null) - { - throw new ArgumentNullException(nameof(htmlHelper)); - } - - if (partialViewName == null) - { - throw new ArgumentNullException(nameof(partialViewName)); - } - return Partial(htmlHelper, partialViewName, htmlHelper.ViewData.Model, viewData: null); } @@ -152,16 +140,6 @@ namespace Microsoft.AspNetCore.Mvc.Rendering string partialViewName, ViewDataDictionary viewData) { - if (htmlHelper == null) - { - throw new ArgumentNullException(nameof(htmlHelper)); - } - - if (partialViewName == null) - { - throw new ArgumentNullException(nameof(partialViewName)); - } - return Partial(htmlHelper, partialViewName, htmlHelper.ViewData.Model, viewData); } @@ -180,21 +158,8 @@ namespace Microsoft.AspNetCore.Mvc.Rendering /// This method synchronously calls and blocks on /// /// - public static IHtmlContent Partial( - this IHtmlHelper htmlHelper, - string partialViewName, - object model) + public static IHtmlContent Partial(this IHtmlHelper htmlHelper, string partialViewName, object model) { - if (htmlHelper == null) - { - throw new ArgumentNullException(nameof(htmlHelper)); - } - - if (partialViewName == null) - { - throw new ArgumentNullException(nameof(partialViewName)); - } - return Partial(htmlHelper, partialViewName, model, viewData: null); } @@ -244,22 +209,9 @@ namespace Microsoft.AspNetCore.Mvc.Rendering /// /// In this context, "renders" means the method writes its output using . /// - public static void RenderPartial( - this IHtmlHelper htmlHelper, - string partialViewName) + public static void RenderPartial(this IHtmlHelper htmlHelper, string partialViewName) { - if (htmlHelper == null) - { - throw new ArgumentNullException(nameof(htmlHelper)); - } - - if (partialViewName == null) - { - throw new ArgumentNullException(nameof(partialViewName)); - } - - var result = htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: null); - result.GetAwaiter().GetResult(); + RenderPartial(htmlHelper, partialViewName, htmlHelper.ViewData.Model, viewData: null); } /// @@ -278,18 +230,7 @@ namespace Microsoft.AspNetCore.Mvc.Rendering string partialViewName, ViewDataDictionary viewData) { - if (htmlHelper == null) - { - throw new ArgumentNullException(nameof(htmlHelper)); - } - - if (partialViewName == null) - { - throw new ArgumentNullException(nameof(partialViewName)); - } - - var result = htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData); - result.GetAwaiter().GetResult(); + RenderPartial(htmlHelper, partialViewName, htmlHelper.ViewData.Model, viewData); } /// @@ -303,10 +244,28 @@ namespace Microsoft.AspNetCore.Mvc.Rendering /// /// In this context, "renders" means the method writes its output using . /// + public static void RenderPartial(this IHtmlHelper htmlHelper, string partialViewName, object model) + { + RenderPartial(htmlHelper, partialViewName, model, viewData: null); + } + + /// + /// Renders HTML markup for the specified partial view. + /// + /// The instance this method extends. + /// + /// The name or path of the partial view used to create the HTML markup. Must not be null. + /// + /// A model to pass into the partial view. + /// A to pass into the partial view. + /// + /// In this context, "renders" means the method writes its output using . + /// public static void RenderPartial( this IHtmlHelper htmlHelper, string partialViewName, - object model) + object model, + ViewDataDictionary viewData) { if (htmlHelper == null) { @@ -318,7 +277,7 @@ namespace Microsoft.AspNetCore.Mvc.Rendering throw new ArgumentNullException(nameof(partialViewName)); } - var result = htmlHelper.RenderPartialAsync(partialViewName, model, viewData: null); + var result = htmlHelper.RenderPartialAsync(partialViewName, model, viewData); result.GetAwaiter().GetResult(); } diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Rendering/HtmlHelperPartialExtensionsTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Rendering/HtmlHelperPartialExtensionsTest.cs index 54e759a57c..23944cc16e 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Rendering/HtmlHelperPartialExtensionsTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Rendering/HtmlHelperPartialExtensionsTest.cs @@ -152,6 +152,7 @@ namespace Microsoft.AspNetCore.Mvc.Rendering { helper => helper.RenderPartial("test"), null, null }, { helper => helper.RenderPartial("test", model), model, null }, { helper => helper.RenderPartial("test", viewData), null, viewData }, + { helper => helper.RenderPartial("test", model, viewData), model, viewData }, }; } }