Почему моя система AddToCart выдает ошибку 404? - PullRequest
0 голосов
/ 26 апреля 2020

Я разрабатывал веб-приложение для клиента в составе команды, используя MVC Framework, и мы работаем над той частью системы, которая позволяет клиентам добавлять товары в корзину. В настоящее время, когда человек выбирает добавить товар в корзину, он выдает ошибку 404.

Это код для CartController:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SystemsGroup.Models;
using Spot.Data;
using Spot.Services.Models;

namespace SystemsGroup.Controllers
{
public class CartController : Controller
{
    public List<CartProduct> cart;
    private Spot.Services.IService.IProductsService _productService;

    // GET: Cart
    public ActionResult AddToCart(int id)
    {
        CartProduct cartItem = new CartProduct();
        Products product = _productService.GetProduct(id);
        cartItem.Quantity = 1;
        cartItem.Id = product.Id;
        cartItem.Name = product.Name;
        cartItem.Description = product.Description;
        cartItem.Price = product.Price;
        cartItem.PartNumber = product.PartNumber;
        List<Products> li = new List<Products>();
        if (Session["cart"] == null)
        {
            li.Add(cartItem);
            Session["cart"] = li;
            ViewBag.cart = li.Count();
            Session["count"] = 1;
        }
        else
        {
            var cart = (List<CartProduct>)Session["cart"];
            li.Add(cartItem);
            Session["cart"] = li;
            ViewBag.cart = li.Count();
            Session["cart"] = cart;
        }
        return RedirectToAction("DisplayCart");
    }

И это код для Модель

namespace Spot.Services.Models
{
    public class CartProduct : Spot.Data.Products
    {
        public int Quantity { get; set; }
    }
}

Файл с именем «SpotModel.Context.Cs» был записан системой и выдает ошибку:

namespace Spot.Data
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;


public partial class SpotContext : DbContext
{
    public SpotContext()
        : base("name=SpotContext")
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

    public virtual DbSet<Cart> Cart { get; set; }
    public virtual DbSet<Customer> Customer { get; set; }
    public virtual DbSet<Products> Products { get; set; }

    public System.Data.Entity.DbSet<SystemsGroup.Models.CartProduct> CartProducts { get; set; }
}
}

Ошибка указывает, что проблема связана с

public System.Data.Entity.DbSet<SystemsGroup.Models.CartProduct> CartProducts { get; set; }

Где говорится, что:

The type or namespace name 'SystemsGroup' could not be found (are you missing a using directive or an assembly reference?)

Редактировать: Это слушание является кодом для представления DiaplyCart:

@model IEnumerable<Spot.Data.Cart>

@{
ViewBag.Title = "DisplayCart";
}

<h2>DisplayCart</h2>

<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
    <th>
        @Html.DisplayNameFor(model => model.Count)
    </th>
    <th>
        @Html.DisplayNameFor(model => model.DateCreated)
    </th>
    <th></th>
</tr>

@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.Count)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.DateCreated)
    </td>
    <td>
        @Html.ActionLink("Edit", "Edit", new { id=item.CartId }) |
        @Html.ActionLink("Details", "Details", new { id=item.CartId }) |
        @Html.ActionLink("Delete", "Delete", new { id=item.CartId })
    </td>
</tr>
}

</table>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...