我是ASP.NET MVC的初學者。我在嘗試從數據庫檢索記錄時遇到錯誤。檢索記錄時出錯
'System.Collections.Generic.List' 不包含定義 '類別名稱'
的LINQ to SQL類:
型號:
namespace MvcApplication1.Models
{
public class CategoryRepository
{
private BusDataClassesDataContext dc = new BusDataClassesDataContext();
public List<tblCategory> GetAllCategory()
{
return dc.tblCategories.ToList();
}
}
}
控制器:
public class CategoryController : Controller
{
//
// GET: /Category/
CategoryRepository cat = new CategoryRepository();
public ActionResult ViewCategory()
{
var category = cat.GetAllCategory().ToList();
return View("ViewCategory", category);
}
}
查看:
<p>
Category Name:<%=Html.Encode(Model.CategoryName)%>
</p>
<p>
Description:<%= Html.Encode(Model.Description)%>
</p>
UPDATE:
@ chamara-難道我的解決方案幫助您解決問題? – PSL 2013-04-22 04:04:44