Skip to content

Wrong syntax highlighting in RenderFragments #12537

@MarvinKlein1508

Description

@MarvinKlein1508

@davidwengier another issue with syntax highlighting in the razor editor. This time within custom renderfragments which I want to re-use in different places. Notice how @Item.Href and @onclick="() => _isExpanded = !_isExpanded" are displayed in brown.

Image
@if (Item.ChildItems.Any())
{
    @if (!string.IsNullOrEmpty(Item.Role))
    {
        <AuthorizeView Roles="@Item.Role">
            <Authorized>
                @NavGroupTemplate
            </Authorized>
        </AuthorizeView>
    }
    else
    {
        @NavGroupTemplate
    }
}
else
{
    <a href="@Item.Href" class="nav-link">@Item.Text</a>
}

@code {
    [Parameter, EditorRequired]
    public NavItem Item { get; set; }

    private bool _isExpanded;

    private RenderFragment NavGroupTemplate => __builder =>
    {
        <a href="@Item.Href" class="nav-link" @onclick="() => _isExpanded = !_isExpanded">@Item.Text</a>
        @if (_isExpanded)
        {

            @foreach (var item in Item.ChildItems)
            {
                <NavMenuItem Item="item" />
            }
        }
    };
}
public class NavItem
{
    /// <summary>
    /// Gets or sets the HyperText Reference (href).
    /// </summary>
    public string? Href { get; set; }

    /// <summary>
    /// Gets or sets the navigation link text.
    /// </summary>
    public string? Text { get; set; }

    /// <summary>
    /// Gets or sets the required authorization role to view this navigation item.
    /// </summary>
    public string? Role { get; set; }

    /// <summary>
    /// Gets or sets the collection of child navigation items.
    /// </summary>
    public IEnumerable<NavItem> ChildItems { get; set; } = [];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions