Skip to content

Enhancement: Blazor / Razor infer @ref definitions from razor language. #7651

@njannink

Description

@njannink

When defining a reference @ref to a html element or razor component you now need to define it double:

<Component @ref="myComponent">Hello Blazor!</Component>

@code {
    private Component myComponent;

    void DoSomething() => myComponent.ShowMessage();
}

You now need to define the type and name twice, both in the razor language and in de code block. Making refactoring / code maintenance more difficult when eg the Component is renamed. It would be a great improvement if the reference in the code block doesnt need to defined aswell. But that it's inferred from the razor language.

Same as for example in Wpf. There your can give a Name to a element and then it's available in the code-behind

So the final solution will be then be:

<Component @ref="myComponent">Hello Blazor!</Component>

@code {
    void DoSomething() => myComponent.ShowMessage();
}

Metadata

Metadata

Labels

area-compilerUmbrella for all compiler issues

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions