我得到這個錯誤,當我想返回viewmodel。Viewmodel想要IEnumerable
傳入字典的模型項目類型爲'Tp1WebStore3.ViewModels.ShoppingCartViewModel',但此字典需要類型爲'System.Collections.Generic.IEnumerable`1 [Tp1WebStore3.Models.Panier]'的模型項。
任何想法是什麼問題?
PanierController.cs
namespace Tp1WebStore3.Controllers
{
public class PanierController : Controller
{
Tp1WebStoreDBEntities db = new Tp1WebStoreDBEntities();
//
// GET: /ShoppingCart/
public ActionResult Index()
{
var cart = ShoppingCart.GetCart(this.HttpContext);
// Set up our ViewModel
var viewModel = new ShoppingCartViewModel
{
CartItems = cart.GetCartItems(),
CartTotal = cart.GetTotal()
};
// Return the view
return View(viewModel); <== the error occurs here
}
ShoppingCartViewModels.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Tp1WebStore3.Models;
namespace Tp1WebStore3.ViewModels
{
public class ShoppingCartViewModel
{
public List<Panier> CartItems { get; set; }
public decimal CartTotal { get; set; }
}
}
你不明白哪部分錯誤? –