Skip to content

Wrong formatting for nested razor code in .razor files #8335

Open
@MarvinKlein1508

Description

@MarvinKlein1508

I have an InputSelect component which will be displayed based on a condition. Within the InputSelect component, I'm generating all available options using an @foreach based on an IEnumerable .

VS Formats my code like this:
grafik

I would expect the code to be formatted like this:

@if (rule.Element is not null)
{
    <InputSelect @bind-Value="rule.ComparisonOperator" id="@($"rule-compare-{rule.GetHashCode()}")" class="form-select" aria-placeholder="Operator">
        @foreach (ComparisonOperator item in GetAllowedOperators(rule.Element))
        {
            <option value="@item">@item</option>
        }
    </InputSelect>
    <label for="@($"rule-compare-{rule.GetHashCode()}")">Operator</label>
}

Instead I get this:

@if (rule.Element is not null)
{
    <InputSelect @bind-Value="rule.ComparisonOperator" id="@($"rule-compare-{rule.GetHashCode()}")" class="form-select" aria-placeholder="Operator">
        @foreach (ComparisonOperator item in GetAllowedOperators(rule.Element))
    {
        <option value="@item">@item</option>
    }
</InputSelect>
    <label for="@($"rule-compare-{rule.GetHashCode()}")">Operator</label>
}

Note all code is also wrapped around by another null check

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions