I am learning MVC 3, MvcContrib grid and when tried to create a view using grid with sort and paging options, I got error. "Could not find a property called 'Customer.CompanyName' on type MvcApplication5.Models.Order" on this line
orders = orders.OrderBy(sort.Column, sort.Direction);
Please let me know whats wrong as the code for Customer table is working correctly may be its just one table and Order table query includes 3 tables?
Controller code is below
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);
}
View Code is here
@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 }));
})