Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. @page "/Item"
  2. @using WebApplication1.Shared
  3. @using WebApplication1.Client.Services;
  4. @inject HttpClient Http
  5. @inherits ItemComponent
  6.  
  7. @if (ItemList != null)
  8. {
  9. <table class="table">
  10. <thead>
  11. <tr>
  12. <th>ID</th>
  13. <th>Name</th>
  14. <th>Category</th>
  15. <th>Metal</th>
  16. <th>Price</th>
  17. <th>Quantity</th>
  18. </tr>
  19. </thead>
  20. <tbody>
  21. @foreach (var item in ItemList)
  22. {
  23. <tr>
  24. <td>@item.ID</td>
  25. <td>@item.Name</td>
  26. <td>@item.Category</td>
  27. <td>@item.Metal</td>
  28. <td>@item.Price</td>
  29. <td>@item.Quantity</td>
  30. </tr>
  31. }
  32. </tbody>
  33. </table>
  34. }
  35.  
  36. @functions{
  37. public ItemModel[] ItemList;
  38. ItemComponent IC = new ItemComponent();
  39.  
  40. protected override async Task OnInitAsync()
  41. {
  42. ItemList = IC.GetItems().Result;
  43. //ItemList = await Http.GetJsonAsync<ItemModel[]>("api/Item/GetItems");
  44. StateHasChanged();
  45. }
  46. }
  47.  
  48. using System.Threading.Tasks;
  49. using WebApplication1.Shared;
  50. using System.Net.Http;
  51. using Microsoft.AspNetCore.Components;
  52. using Microsoft.AspNetCore.Blazor;
  53.  
  54. namespace WebApplication1.Client.Services
  55. {
  56. public class ItemComponent
  57. {
  58. public async Task<ItemModel[]> GetItems()
  59. {
  60. ItemModel[] ItemList;
  61. HttpClient Http = new HttpClient();
  62. ItemList = await Http.GetJsonAsync<ItemModel[]>("api/Item/GetItems");
  63. return ItemList;
  64. }
  65.  
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement