我是 ASP.NET MVC 的初学者。尝试从数据库中检索记录时出现错误。
“System.Collections.Generic.List”不包含“CategoryName”的定义
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>
更新: