Document Context="Item" requirement for Web Forms compatibility#310
Document Context="Item" requirement for Web Forms compatibility#310csharpfritz merged 4 commits intodevfrom
Conversation
…lity After extensive research and testing, I've determined that Blazor's Context attribute is a special compile-time directive that cannot have its default value changed from "context" to "Item" at the component definition level. Key findings: - Adding [Parameter] public string Context breaks Blazor's Razor compiler - Context is NOT a regular parameter - it's a special directive - Microsoft's own components (like Virtualize) also use default "context" - The only solution is to document that users should use Context="Item" Updated documentation to clarify Web Forms compatibility requirement. Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com>
|
@copilot can we introduce a default Context in the base component that sets the context to Item and allows override? |
Unfortunately, no. I tested this approach and it breaks Blazor's Razor compiler. What I tried: Result:
Root cause: Current solution: <Repeater Items="data" ItemType="Widget" Context="Item">
<ItemTemplate>@Item.Name</ItemTemplate>
</Repeater>This limitation exists in the Blazor framework itself - even Microsoft's components (like |
|
@copilot Let's add notes about this context compatibility to the docs for migration |
Added comprehensive documentation about using Context="Item" for Web Forms compatibility across all data-bound control documentation and migration guides. Changes: - Migration readme: New Step 5.6 explaining template context differences - Migration readiness: Added Context="Item" to high-level requirements - Repeater docs: Added Usage Notes with Context guidance and example - ListView docs: Enhanced Usage Notes with Context information - FormView docs: Added Usage Notes with Context guidance - GridView docs: Enhanced Blazor Notes with TemplateField context info All documentation now clearly explains that Context="Item" should be used for Web Forms compatibility to access items as @item instead of @context. Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com>
Addressed code review comments: - Clarified Web Forms comparison to strongly-typed Item property - Improved migration_readiness structure with Data-Bound Controls subsection - Standardized ListView Usage Notes formatting for consistency Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com>
Done! Added Context compatibility notes to migration docs in commits 86d9491 and 42ebb08. Migration documentation:
Component documentation:
All data-bound controls (Repeater, DataList, ListView, FormView, GridView/TemplateField) now have clear documentation about using |
Blazor's
Contextattribute is a Razor compiler directive, not a regular parameter. Cannot override the default "context" name at component definition level.Research Findings
Attempted approach from issue comments:
Result: Breaks Razor compilation. The compiler's special handling of
ContextforRenderFragment<T>is bypassed, causing "The name 'Item' does not exist in the current context" errors.Microsoft's own components (e.g.,
Virtualize) use the framework default "context". This is hard-coded in Blazor's Razor compiler.Changes
Migration Documentation
Itemproperty and Blazor's@contextvariableComponent Documentation
Updated all five data-bound control docs with Context usage guidance:
Usage
Users must specify context name at component usage site:
This achieves the same Web Forms-style
@Itemexperience (matching Web Forms' strongly-typedItemproperty) with one attribute per component.All documentation now provides clear, actionable guidance for developers migrating data-bound controls from Web Forms to Blazor.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.