Answer the question
In order to leave comments, you need to log in
Error 404 when displaying the page, although the request was registered correctly by the request?
@model ShopCartViewModel
<div class="container">
@foreach (var el in Model.shopCart.listShopItems)
{
<div class="alert alert-warning mt-3">
<b>Адресс:</b>@el.realty.adress<br />
<b>Цена:</b>@el.realty.price.ToString("c")
</div>
}
<hr />
<div class="btn btn-danger" asp-controller="Order">Оплатить</div>
</div>
<h2>Вся недвижимость</h2>
<h3>@Model.shopCart</h3>
<div class="row mt-5 mb-4">
@{
foreach (Realty realt in Model.shopCart)
{
@Html.Partial("AllRealty", realt)
}
}
</div>
public class ShopCartController : Controller
{
private readonly IAllRealty _realtyRep;
private readonly ShopCart _shopCart;
public ShopCartController(IAllRealty realRep, ShopCart shopCart)
{
_realtyRep = realRep;
_shopCart = shopCart;
}
public ViewResult Index()
{
var items = _shopCart.GetShopItems();
_shopCart.listShopItems = items;
var obj = new ShopCartViewModel
{
shopCart = _shopCart
};
return View(obj);
}
public RedirectToActionResult addToCart(int id)
{
var item = _realtyRep.Realty.FirstOrDefault(i => i.id == id);
if (item != null)
{
_shopCart.AddToCart(item);
}
return RedirectToAction("Index");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question