Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @page "/Item"
- @using WebApplication1.Shared
- @using WebApplication1.Client.Services;
- @inject HttpClient Http
- @inherits ItemComponent
- @if (ItemList != null)
- {
- <table class="table">
- <thead>
- <tr>
- <th>ID</th>
- <th>Name</th>
- <th>Category</th>
- <th>Metal</th>
- <th>Price</th>
- <th>Quantity</th>
- </tr>
- </thead>
- <tbody>
- @foreach (var item in ItemList)
- {
- <tr>
- <td>@item.ID</td>
- <td>@item.Name</td>
- <td>@item.Category</td>
- <td>@item.Metal</td>
- <td>@item.Price</td>
- <td>@item.Quantity</td>
- </tr>
- }
- </tbody>
- </table>
- }
- @functions{
- public ItemModel[] ItemList;
- ItemComponent IC = new ItemComponent();
- protected override async Task OnInitAsync()
- {
- ItemList = IC.GetItems().Result;
- //ItemList = await Http.GetJsonAsync<ItemModel[]>("api/Item/GetItems");
- StateHasChanged();
- }
- }
- using System.Threading.Tasks;
- using WebApplication1.Shared;
- using System.Net.Http;
- using Microsoft.AspNetCore.Components;
- using Microsoft.AspNetCore.Blazor;
- namespace WebApplication1.Client.Services
- {
- public class ItemComponent
- {
- public async Task<ItemModel[]> GetItems()
- {
- ItemModel[] ItemList;
- HttpClient Http = new HttpClient();
- ItemList = await Http.GetJsonAsync<ItemModel[]>("api/Item/GetItems");
- return ItemList;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement