I am attempting to include a parameter in a component based on a condition, but I'm not sure of the syntax to use:
<Select @if (transaction.Id == 4) { Value="1" }>
Full code snippet:
@foreach (var transaction in Transactions)
{
<Select @if (transaction.Id == 4) { Value="1" }>
<SelectOption Value="1">Option 1</SelectOption>
<SelectOption Value="2">Option 2</SelectOption>
</Select>
}
So in short, I only want the Value parameter passed to the Select component when a condition is satisfied. The Select Component is a custom component.
What is the correct syntax to achieve the above?
CodePudding user response:
Try it like this using a ternary
<select value=@(transaction.Id ==4 ? "1":"")></select>
Nb: not sure if your select is a standard HTML select, as its starts with an uppercase S indicating that it's a component