On other occasions I have been able to solve this problem using ternaries with the difference that it was within html code as shown below: <td>@(InfoMiddleware.Active? "Active": "Disable")</td>
The detail is that now I use Telerik components and within it it does not let me use the ternary since the error thrown is "The expression does not have a name".
I need this table to show the active/disable status..
The code you used makes use of telerik: Error: `
@if (middlewareHeader == null)
{
<div class="alert alert-success w-100">
<p><i class="fas fa-spin fa-spinner"></i> The middlewares is loading...</p>
</div>
}
else
{
@switch (isSelected)
{
case true:
<TelerikGrid Data="middlewareHeader" Sortable="true" Pageable="true" FilterMode="GridFilterMode.FilterMenu">
<GridToolBar>
<GridSearchBox Placeholder="@Placeholder"
Width="@(SearchBoxWidth >= 100 ? SearchBoxWidth +"px" : "100px")"
DebounceDelay="@DebounceDelay">
</GridSearchBox>
</GridToolBar>
<GridColumns>
<GridColumn Field="@nameof(MiddlewareModel.MiddlewareId)"
Title="Middleware"></GridColumn>
<GridColumn Field="@nameof(MiddlewareModel.Description)"
Title="Description"></GridColumn>
<GridColumn Field="@nameof(MiddlewareModel.Active ? "Active" : "Disable")"
Title="Status"></GridColumn>
<GridColumn Field="@nameof(MiddlewareModel.MiddlewareId)"
Title="Navigation">
<Template>
<TelerikButton @onclick="@(() => Navigation.NavigateTo($"/Environments/{environmentId}/Middlewares/{(context as MiddlewareModel).MiddlewareId}"))">More Information</TelerikButton>
</Template>
</GridColumn>
</GridColumns>
</TelerikGrid>
break;
case false:
<div class="container">
@foreach (var middleware in middlewareHeader)
{
<CardMiddleware MiddlewareId="@middleware.MiddlewareId"
Description="@middleware.Description"
Active="@middleware.Active"
url="@($"/Environments/{environmentId}/Middlewares/{middleware.MiddlewareId}")">
</CardMiddleware>
}
</div>
break;
}
}
`
The issue is not with Telerik.
The statement:
nameof(MiddlewareModel.Active ? "Active" : "Disable")
will give the same error in any context.
If you have an instance of Middleware class to work with then you'd use:
middlewareInstance.Active ? "Active" : "Disable"
to create the text Active
or Disable
based on the boolean value of Active property on middlewareInstance
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.