Skip to content

Support multiple 'bind-Property' on components #16178

Closed
@maraf

Description

@maraf

Hi there,
I have a user component with multiple properties which I want to bind to.

<User bind-Name="@UserName" bind-IsActive="@UserIsActive" />
  1. In User, if I define *Changed delegate properties for both Name and IsActive:
<input type="text" bind="@Name" />
<input type="checkbox" bind="@IsActive" />

@functions
{
    public string Name { get; set; }
    public Action<string> NameChanged { get; set; }
    public bool IsActive { get; set; }
    public Action<bool> IsActiveChanged { get; set; }
}

Build fails with:

D:\Development\.NuGet\microsoft.aspnetcore.blazor.build\0.2.0\targets\RazorCompilation.targets(281,5): error : rzc generate exited with code 1. [D:\Development\Maraf\Money\src\Money.UI.Blazor\Money.UI.Blazor.csproj]
  1. When I originally defined only a single Changed property, generated code looked like:
builder.OpenComponent<Money.UI.Blazor.Components.User>(14);
builder.AddAttribute(15, "Name", Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(UserName));
builder.AddAttribute(16, "NameChanged", new System.Action<System.String>(__value => UserName = __value));
builder.AddAttribute(17, "Name", Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(UserIsActive));
builder.AddAttribute(18, "NameChanged", new System.Action<System.String>(__value => UserIsActive = __value));
builder.CloseComponent();

Which tried to bind both expressions to property Name and failed build with:

obj\Debug\netstandard2.0\Pages\Summary.g.cs(61,112): error CS0029: Cannot implicitly convert type 'string' to 'bool' [D:\Development\Maraf\Money\src\Money.UI.Blazor\Money.UI.Blazor.csproj]

Metadata

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor Components

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions