我有一个MVC3 Telerik应用程序。这是我的控制者:
[GridAction]
public ActionResult Index(GridCommand command)
{
IEnumerable<Order> data = GetData(command);
var dataContext = new NorthwindDataContext();
//Required for pager configuration
ViewData["total"] = dataContext.Orders.Count();
return View(data);
}
[GridAction(EnableCustomBinding = true)]
public ActionResult _CustomBinding(GridCommand command)
{
IEnumerable<Order> data = GetData(command);
var dataContext = new NorthwindDataContext();
return View(new GridModel
{
Data = data,
Total = dataContext.Orders.Count()
});
}
//Utility method which does custom paging and sorting using Linq
private static IEnumerable<Order> GetData(GridCommand command)
{
var dataContext = new NorthwindDataContext();
IQueryable<Order> data = dataContext.Orders;
if (command.PageSize > 0)
{
data = data.Skip((command.Page - 1) * command.PageSize);
}
data = data.Take(5);
return data;
}
这是我的剃须刀查看:
@model IEnumerable<Telerik.Order>
@(Html.Telerik().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.OrderID).Width(100);
columns.Bound(o => o.Customer.ContactName).Width(200);
columns.Bound(o => o.ShipAddress);
columns.Bound(o => o.OrderDate).Format("{0:MM/dd/yyyy}").Width(100);
})
.DataBinding(dataBinding =>
{
dataBinding.Ajax().Select("_CustomBinding", "Home").Enabled(true);
})
.Pageable(pager => pager.Total((int)ViewData["total"]))
.EnableCustomBinding(true)
.Sortable()
)
当我运行应用程序时,它加载正常,但是当我点击底部分页行中的数字时,我得到:
Error! The requested URL returned 500- Internal server error
它调用我的函数_CustomBinding,当我单步执行它时不会抛出错误。是什么导致了这个错误?
答案 0 :(得分:0)
这意味着_CustomBinding方法中发生了服务器端异常。您可以检查实际的服务器响应是什么 - 它将包含堆栈跟踪。使用Fiddler或浏览器的开发人员工具来检查服务器响应是什么。