我不斷收到一個錯誤,指出:MVC控制器和存儲庫模型
傳遞到字典的模型項的類型爲「HomebaseSystemNew.Controllers.ProductRepository」,但這部詞典需要類型HomebaseSystemNew的」典範項目。 Models.Product」
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<HomebaseSystemNew.Models.Product>" %>
我的倉庫:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HomebaseSystemNew.Models;
namespace HomebaseSystemNew.Controllers
{
public class ProductRepository
{
public Product GetProductID(int Pid)
{
DatabaseLinkedDataContext db = new DatabaseLinkedDataContext();
return db.Products.FirstOrDefault(ans => ans.Pid == Pid);
}
}
我的控制器:
using System.Linq;
using System.Web.Mvc;
using HomebaseSystemNew.Models;
namespace HomebaseSystemNew.Controllers
{
public class ProductsController : Controller
{
public ActionResult EditProduct(int id)
{
ProductRepository repo = new ProductRepository();
repo.GetProductID(id);
return View(repo);
}
}
你真的應該開始張貼前接受了一些答案更多... – James