From acd88d08ba3ef792006f0e51bff85e4fa4bb8a5e Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Tue, 2 Feb 2016 16:14:05 -0800 Subject: [PATCH] Enable invoking a `ViewComponent` without arguments inside of a controller. - Also updated doc comments to properly reflect `ViewComponent` `arguments` parameter. --- .../Controller.cs | 38 ++++++++++++++++--- .../IViewComponentHelper.cs | 12 +++--- .../ControllerUnitTestabilityTests.cs | 4 +- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Controller.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Controller.cs index d71833454e..b839094e61 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Controller.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Controller.cs @@ -209,6 +209,32 @@ namespace Microsoft.AspNetCore.Mvc }; } + /// + /// Creates a by specifying the name of a view component to render. + /// + /// + /// The view component name. Can be a view component + /// or + /// . + /// The created object for the response. + [NonAction] + public virtual ViewComponentResult ViewComponent(string componentName) + { + return ViewComponent(componentName, arguments: null); + } + + /// + /// Creates a by specifying the of a view component to + /// render. + /// + /// The view component . + /// The created object for the response. + [NonAction] + public virtual ViewComponentResult ViewComponent(Type componentType) + { + return ViewComponent(componentType, arguments: null); + } + /// /// Creates a by specifying the name of a view component to render. /// @@ -217,9 +243,9 @@ namespace Microsoft.AspNetCore.Mvc /// or /// . /// - /// An anonymous containing arguments to be passed to the invoked view component method. - /// Alternatively, an instance containing - /// the invocation arguments. + /// An with properties representing arguments to be passed to the invoked view component + /// method. Alternatively, an instance + /// containing the invocation arguments. /// /// The created object for the response. [NonAction] @@ -240,9 +266,9 @@ namespace Microsoft.AspNetCore.Mvc /// /// The view component . /// - /// An anonymous containing arguments to be passed to the invoked view component method. - /// Alternatively, an instance containing - /// the invocation arguments. + /// An with properties representing arguments to be passed to the invoked view component + /// method. Alternatively, an instance + /// containing the invocation arguments. /// /// The created object for the response. [NonAction] diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/IViewComponentHelper.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/IViewComponentHelper.cs index 8bfcc4ce16..6c5bcb91da 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/IViewComponentHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/IViewComponentHelper.cs @@ -17,9 +17,9 @@ namespace Microsoft.AspNetCore.Mvc /// /// The name of the view component. /// - /// An anonymous containing arguments to be passed to the invoked view component method. - /// Alternatively, an instance containing - /// the invocation arguments. + /// An with properties representing arguments to be passed to the invoked view component + /// method. Alternatively, an instance + /// containing the invocation arguments. /// /// A that on completion returns the rendered . /// @@ -30,9 +30,9 @@ namespace Microsoft.AspNetCore.Mvc /// /// The view component . /// - /// An anonymous containing arguments to be passed to the invoked view component method. - /// Alternatively, an instance containing - /// the invocation arguments. + /// An with properties representing arguments to be passed to the invoked view component + /// method. Alternatively, an instance + /// containing the invocation arguments. /// /// A that on completion returns the rendered . /// diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ControllerUnitTestabilityTests.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ControllerUnitTestabilityTests.cs index 636171759c..1eed7008e4 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ControllerUnitTestabilityTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/ControllerUnitTestabilityTests.cs @@ -560,7 +560,7 @@ namespace Microsoft.AspNetCore.Mvc var controller = new TestabilityController(); // Act - var result = controller.ViewComponent("TagCloud", arguments: null); + var result = controller.ViewComponent("TagCloud"); // Assert Assert.NotNull(result); @@ -575,7 +575,7 @@ namespace Microsoft.AspNetCore.Mvc var controller = new TestabilityController(); // Act - var result = controller.ViewComponent(typeof(TagCloudViewComponent), arguments: null); + var result = controller.ViewComponent(typeof(TagCloudViewComponent)); // Assert Assert.NotNull(result);