Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to register component event without ParameterAttribute #15870

Closed
fs86 opened this issue Jun 22, 2018 · 3 comments
Closed

Unable to register component event without ParameterAttribute #15870

fs86 opened this issue Jun 22, 2018 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@fs86
Copy link

fs86 commented Jun 22, 2018

I noticed that events in custom components can only be registered from the parent component if ParameterAttribute is present. I have followed the example of @danroth27, which is described here: #5504

My custom component:

<input type="text" value="@Value" onchange="@OnInputChanged" />

@functions
{
    [Parameter] string Value { get; set; }
    public Action<string> ValueChanged { get; set; }
    void OnInputChanged(UIChangeEventArgs e)
    {
        Value = e.Value.ToString();
        ValueChanged(Value);
    }
}

My parent component:

<MyCustomComponent Value="@Product.Name" ValueChanged="@OnValueChanged" />

@functions
{
    void OnValueChanged(string value)
    {
        Product.Name = value;
        StateHasChanged();
    }
}

Output: "Cannot convert method group 'OnValueChanged' to non-delegate type 'object'. Did you intend to invoke the method?"

If I add [Parameter] to my event, everything works fine.

@chucker
Copy link

chucker commented Jun 23, 2018

Since @danroth27's example is from before Blazor 0.3, my guess this is by design, since 0.3's release notes state:

Upgrade an existing project to Blazor 0.3.0
To upgrade an existing Blazor project from 0.2.0 to 0.3.0:
[..]
Update component parameters to not be public and to add the [Parameter] attribute.

@fs86
Copy link
Author

fs86 commented Jun 25, 2018

Many thanks for your response. Then it's probably not a bug.

@SteveSandersonMS
Copy link
Member

Thanks for answering, @chucker!

@mkArtakMSFT mkArtakMSFT transferred this issue from dotnet/blazor Oct 27, 2019
@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Oct 27, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

4 participants