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

Need clarification on using @ prefix on Razor component's attribute values #34564

Open
nicholasyin opened this issue Jan 25, 2025 · 2 comments
Open

Comments

@nicholasyin
Copy link

nicholasyin commented Jan 25, 2025

Description

Image

For one thing, the example below doesn't seem to follow the above convention of not using @ prefix for non-literal variable in attribute values.
In addition, I think adding @ is more reasonable because Count="ct" would intuitively give me the impression that ct is a regular string assigned to Count variable.

Page URL

https://learn.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-9.0#route-parameters

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/components/index.md

Document ID

31ad18df-1904-bbdd-cfed-8d0d0267c10e

Article author

@guardrex

Metadata

  • ID: 81a32115-33f8-7d06-aaf0-b8ce918b5527
  • Service: aspnet-core
  • Sub-service: blazor

Related Issues

Copy link
Contributor

💃🕺🥳 Happy New Year! 🎈🎆🍾🥂🎉

Stand-by! ... A green dinosaur 🦖 will be along shortly to assist.

@guardrex
Copy link
Collaborator

Thanks for mentioning this, @nicholasyin. Indeed! I'd like to update the example to match the text.

We did make a change a couple of years ago, telling devs that we wouldn't generally prefix with @ when it wasn't required for component parameter values. Before that, yes, we did always use @ in these examples, as the Parameter2 component shows.

WRT ...

I think adding @ is more reasonable because Count="ct" would intuitively give me the impression that ct is a regular string assigned to Count variable.

That's going to end up being a personal (or organizational) preference on your end. Management (Dan Roth) has decided that we'll not do it in framework test code and documentation examples. Of course, you're welcome to do it in your own apps. The usual recommendation applies: We'd simply suggest that devs be consistent in their choice within an app and even across the apps of their organization.

I'll be back in the office ... well ... at my desk 😆 (I'm remote) ... on Monday morning. I'll work on this first thing and resolve it, including adding some context to the article on the subject. I'll ping u on the PR when it goes up.

Thanks for the issue! Have a great weekend and Happy New Year! 💃🕺🥳🍾

@guardrex guardrex moved this from Triage to P0/P1 - High Priority in Blazor.Docs Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: P0/P1 - High Priority
Development

No branches or pull requests

2 participants