我正在学习 MVC 3、MvcContrib 网格,当尝试使用带有排序和分页选项的网格创建视图时,出现错误。“在 MvcApplication5.Models.Order 类型上找不到名为 'Customer.CompanyName' 的属性” 在此行
orders = orders.OrderBy(sort.Column, sort.Direction);
请让我知道有什么问题,因为 Customer 表的代码工作正常可能只是一个表,而 Order 表查询包括 3 个表?
控制器代码如下
public ActionResult Index(GridSortOptions sort, int? page)
{
IEnumerable<Order> orders = db.Orders.Include(o => o.Customer).Include(o => o.Employee).Include(o => o.Shipper);
if (sort.Column != null)
{
orders = orders.OrderBy(sort.Column, sort.Direction);
}
//orders = orders.AsPagination(page ?? 1, 25);
ViewData["sort"] = sort;
return View(orders);
}
查看代码在这里
@model IEnumerable<MvcApplication5.Models.Order>
@using MvcContrib.UI.Grid;
@using MvcContrib.UI.Pager;
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@Html.Grid(Model).Sort((GridSortOptions)ViewData["sort"]).Columns(col => {
col.For(o => o.Customer.CompanyName).Named("Customer").Sortable(true).SortColumnName("Customer.CompanyName");
col.For(o => o.Employee.LastName).Named("Employee");
col.For(o => o.OrderDate).Named("Order Date");
col.For(o => o.RequiredDate).Named("Required Date");
col.For(o => o.ShippedDate).Named("Shipped Date");
col.For(o => o.Shipper.CompanyName).Named("Shipper");
col.For(o => o.Freight).Named("Frieght");
col.For(o => o.ShipName).Named("Ship Name");
col.For(o => o.ShipAddress).Named("Ship Address");
col.For(o => o.ShipCountry).Named("Ship Country");
col.For(o => @Html.ActionLink("Edit", "Edit", new { id = o.OrderID }));
col.For(o => @Html.ActionLink("Details", "Details", new { id = o.OrderID }));
col.For(o => @Html.ActionLink("Delete", "Delete", new { id = o.OrderID }));
})