D
D
dog-hot2021-03-17 14:27:09
ASP.NET
dog-hot, 2021-03-17 14:27:09

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");
        }
    }

6051e769089cc334761665.png
6051e77b35434390087108.png
6051e7c60543e944196654.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BasiC2k, 2021-03-17
@dog-hot

404 means page not found. Possible reasons:
- there is no controller with the same name;
- aliases for areas are incorrectly configured.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question