dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.36k stars 9.99k forks source link

Better experience for passing ChildContent with CaptureUnmatchedParameters #10709

Closed rynowak closed 4 years ago

rynowak commented 5 years ago

Using a component like InputText that captures unmatched parameters, but doesn't accept a child content can result in some silent-ish failures if you try to provide one.

Since passing a content to the builder is a different gesture than passing an attribute, the result is that Blazor will ToString the delegate and put it in the attribute.

I'm not totally concerned about a breaking change since this doesn't do anything useful.

image

Sample code:

@page "/"
@using Microsoft.AspNetCore.Components.Forms

<EditForm Model="@p">
    <InputText ChildContent="@((RenderFragment)RenderIt)" @bind-Value="@p.Name"></InputText>
</EditForm>

@functions {
    Person p = new Person();
    public class Person
    {
        public string Name { get; set; }
    }

    void RenderIt(Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder b)
    {
        b.OpenElement(0, "strong");
        b.AddContent(1, "YO");
        b.CloseElement();
    }
}
rynowak commented 5 years ago

My recommendation on this is backlog and wait for feedback, doesn't seem urgent.

SteveSandersonMS commented 4 years ago

Due to lack of any feedback in ~18 months it seems this is not a clear need, so I'll close it. We can always reconsider in the future.