Добавил таблицу для отображения продуктов на странице /Product/Index

parent 10071420
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Store.Models;
namespace Store.Controllers
{
......@@ -6,6 +9,28 @@ namespace Store.Controllers
{
public IActionResult Index()
{
List<Product> products = new List<Product>
{
new Product
{
Id = Guid.NewGuid().ToString(),
Name = "Asus A234",
Amount = 100,
Brand = "Asus",
Category = "TV"
},
new Product
{
Id = Guid.NewGuid().ToString(),
Name = "Asus A674",
Amount = 150,
Brand = "Asus",
Category = "TV"
}
};
ViewBag.products = products;
return View();
}
}
......
namespace Store.Models
{
public class Product
{
public string Id { get; set; }
public string Name { get; set; }
public string Category { get; set; }
public string Brand { get; set; }
public int Amount { get; set; }
}
}
@using Store.Models
@{
Layout = "_MainLayout";
}
<h1>Hello</h1>
<h2>Last products:</h2>
<hr/>
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Category</th>
<th scope="col">Amount</th>
<th scope="col">Brand</th>
</tr>
</thead>
<tbody>
@foreach (Product product in ViewBag.products)
{
<tr>
<th scope="row">@product.Id</th>
<td>@product.Name</td>
<td>@product.Category</td>
<td>@product.Amount</td>
<td>@product.Brand</td>
</tr>
}
</tbody>
</table>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment