Stefanidze
Stefanidze
CC#
Created by Stefanidze on 3/25/2024 in #help
✅ How can i bind a value to an item on render in blazor?
I use the following layout:
inject NevigationManager nav

<ul>
@for (int i = 0; i < ItemList.count, i++){
<li @onclick="() => redirect(i)">
@* some code *@
</li>
}
</ul>
@code{
public IReadOnlyCollection<Item>? ItemList;

//some code

void redirect(int index){
nav.NavigateTo($"/db?item={ItemList!.ElementAt(index).Id}");
}
inject NevigationManager nav

<ul>
@for (int i = 0; i < ItemList.count, i++){
<li @onclick="() => redirect(i)">
@* some code *@
</li>
}
</ul>
@code{
public IReadOnlyCollection<Item>? ItemList;

//some code

void redirect(int index){
nav.NavigateTo($"/db?item={ItemList!.ElementAt(index).Id}");
}
But when the user clicks on an item it tries to get next i value, for example if a database has 3 items (including null item) i will be 4, resulting in an IndexOutOfRangeException. How can i make i value somehow bind to the item on render in a way that i can get it in code?
12 replies
CC#
Created by Stefanidze on 3/22/2024 in #help
Can i use async/await in class constructors?
I want my class constructor to send data to the database, so every instance of the class is synced with the corresponding item in the database. The problem is that database uses async, and i want to wait for the database to process the request, to output unique id, for me to use it later. Is there any way i can do that?
6 replies
CC#
Created by Stefanidze on 12/31/2023 in #help
What is the up-to-date version of AspNet.WebAPI?
I am upgrading my console application to include Web Api, so i changed the sdk from Microsoft.NET.Sdk to Microsoft.NET.Sdk.Web, and this resulted in project restoring Microsoft.AspNet.WebApi and Microsoft.AspNet.WebApi.Cors. But now when i build or run my project i get warning NU1701 In the output it shows that it cannot restore these two packages with net8.0 but instead they work only with .NET framework. From this i assume that these packages are legacy and need to be replaced, but i couldn't find any information about it. Is there any up-to-date version, for example based on AspNetCore? I use VSCode. Full output of the warning
8 replies