我一直收到一个错误说:
传递到字典中的模型项的类型为"HomebaseSystemNew.Controllers.ProductRepository",但此字典需要"HomebaseSystemNew.Models.Product"类型的模型项.
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<HomebaseSystemNew.Models.Product>" %>
Run Code Online (Sandbox Code Playgroud)
我的存储库:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
您将在"视图而不是产品"中返回存储库.把它改成这个:
var product = repo.GetProductID(id);
return View(product );
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
130 次 |
最近记录: |