Skip to content

Commit 79a1769

Browse files
committed
fixup
1 parent 3fe0e30 commit 79a1769

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

src/Components/test/E2ETest/ServerExecutionTests/ComponentWithParametersTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public ComponentWithParametersTest(
2727
}
2828

2929
[Fact]
30-
public void PassingParametersToComponentsWorks()
30+
public void PassingParametersToComponentsFromThePageWorks()
3131
{
3232
Navigate("/prerendered/componentwithparameters?QueryValue=testQueryValue");
3333

src/Components/test/testassets/TestServer/Pages/MultipleComponents.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
</head>
1111
<body>
1212
<div id="test-container">
13-
<component type="typeof(GreeterComponent)" render-mode="ServerPrerendered" />
14-
<component type="typeof(GreeterComponent)" render-mode="Server" />
13+
@(await Html.RenderComponentAsync<GreeterComponent>(RenderMode.ServerPrerendered))
14+
@(await Html.RenderComponentAsync<GreeterComponent>(RenderMode.Server))
1515
<component type="typeof(GreeterComponent)" render-mode="Static" param-name='"John"' />
1616
<component type="typeof(GreeterComponent)" render-mode="Server"/>
1717
<div id="container">

src/Mvc/Mvc.ViewFeatures/ref/Microsoft.AspNetCore.Mvc.ViewFeatures.netcoreapp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ public enum Html5DateRenderingMode
324324
}
325325
public static partial class HtmlHelperComponentExtensions
326326
{
327+
public static System.Threading.Tasks.Task<Microsoft.AspNetCore.Html.IHtmlContent> RenderComponentAsync(this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper htmlHelper, System.Type componentType, Microsoft.AspNetCore.Mvc.Rendering.RenderMode renderMode, object parameters) { throw null; }
327328
public static System.Threading.Tasks.Task<Microsoft.AspNetCore.Html.IHtmlContent> RenderComponentAsync<TComponent>(this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper htmlHelper, Microsoft.AspNetCore.Mvc.Rendering.RenderMode renderMode) where TComponent : Microsoft.AspNetCore.Components.IComponent { throw null; }
328329
public static System.Threading.Tasks.Task<Microsoft.AspNetCore.Html.IHtmlContent> RenderComponentAsync<TComponent>(this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper htmlHelper, Microsoft.AspNetCore.Mvc.Rendering.RenderMode renderMode, object parameters) where TComponent : Microsoft.AspNetCore.Components.IComponent { throw null; }
329330
}

src/Mvc/Mvc.ViewFeatures/src/Rendering/HtmlHelperComponentExtensions.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Mvc.Rendering
1616
public static class HtmlHelperComponentExtensions
1717
{
1818
/// <summary>
19-
/// Renders the <typeparamref name="TComponent"/> <see cref="IComponent"/>.
19+
/// Renders the <typeparamref name="TComponent"/>.
2020
/// </summary>
2121
/// <param name="htmlHelper">The <see cref="IHtmlHelper"/>.</param>
2222
/// <param name="renderMode">The <see cref="RenderMode"/> for the component.</param>
@@ -25,7 +25,7 @@ public static Task<IHtmlContent> RenderComponentAsync<TComponent>(this IHtmlHelp
2525
=> RenderComponentAsync<TComponent>(htmlHelper, renderMode, parameters: null);
2626

2727
/// <summary>
28-
/// Renders the <typeparamref name="TComponent"/> <see cref="IComponent"/>.
28+
/// Renders the <typeparamref name="TComponent"/>.
2929
/// </summary>
3030
/// <param name="htmlHelper">The <see cref="IHtmlHelper"/>.</param>
3131
/// <param name="parameters">An <see cref="object"/> containing the parameters to pass
@@ -36,15 +36,35 @@ public static Task<IHtmlContent> RenderComponentAsync<TComponent>(
3636
this IHtmlHelper htmlHelper,
3737
RenderMode renderMode,
3838
object parameters) where TComponent : IComponent
39+
=> RenderComponentAsync(htmlHelper, typeof(TComponent), renderMode, parameters);
40+
41+
/// <summary>
42+
/// Renders the specified <paramref name="componentType"/>.
43+
/// </summary>
44+
/// <param name="htmlHelper">The <see cref="IHtmlHelper"/>.</param>
45+
/// <param name="componentType">The component type.</param>
46+
/// <param name="parameters">An <see cref="object"/> containing the parameters to pass
47+
/// to the component.</param>
48+
/// <param name="renderMode">The <see cref="RenderMode"/> for the component.</param>
49+
public static Task<IHtmlContent> RenderComponentAsync(
50+
this IHtmlHelper htmlHelper,
51+
Type componentType,
52+
RenderMode renderMode,
53+
object parameters)
3954
{
4055
if (htmlHelper is null)
4156
{
4257
throw new ArgumentNullException(nameof(htmlHelper));
4358
}
4459

60+
if (componentType is null)
61+
{
62+
throw new ArgumentNullException(nameof(componentType));
63+
}
64+
4565
var viewContext = htmlHelper.ViewContext;
4666
var componentRenderer = viewContext.HttpContext.RequestServices.GetRequiredService<IComponentRenderer>();
47-
return componentRenderer.RenderComponentAsync(viewContext, typeof(TComponent), renderMode, parameters);
67+
return componentRenderer.RenderComponentAsync(viewContext, componentType, renderMode, parameters);
4868
}
4969
}
5070
}

0 commit comments

Comments
 (0)