使用
1)kendo mvc grid(asp.net MVC的telerik UI)在我看来(Q1-2015)
2)使用ODATA终点(类似于文章http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v3/calling-an-odata-service-from-a-net-client) - 消费asp.net web api(odata)
控制器代码
public ActionResult LoadGrid([DataSourceRequest]DataSourceRequest request)
{
if (Request.Cookies["myAPIKeyCookie"] != null)
{
var cookieValue = Request.Cookies["myAPIKeyCookie"].Value;
using (var context = new MyApiClientContext(cookieValue))
{
IQueryable<User> users = context.MyApiContainer.Users;// did a watch - users contains data.
var result = users.ToDataSourceResult(request);// throws an error here - the request url is appended with $count e.g. https://myurl/odata/users()?$count - Shouldnt the toDataSourceResult method add the pagesize as count here automatically?
return Json(result);
}
}
else
{
return RedirectToAction("Index", "Login");
}
return Json(null);
}
我的观点
@(Html.Kendo().Grid<User>()
.Name("GridAjax")
.DataSource(ds => ds.Ajax()
.Read(readFrom => readFrom.Action("LoadGrid", "Users"))
.Model(m => m.Id(model => model.Id))
.PageSize(5)
)
.Columns(columns =>
{
columns.Bound(u => u.Id).Visible(false);
columns.Bound(u => u.DisplayName);
columns.Bound(u => u.Email);
columns.Bound(u => u.ManagerName);
})
.Pageable()
.Sortable()
.Filterable()
.Editable(e => e.Mode(GridEditMode.InLine))
)
在线路上遇到错误&#34; users.ToDataSourceResult&#34;。
以下的例外情况{&#34;消息&#34;:&#34; OData路径无效。&#34;,&#34; ExceptionMessage&#34;:&#34;检测到无效操作。 &#39; $计数&#39;不是可以绑定到&#39; Collection([MyApi.Domain.Entities.User Nullable = False])&#39;。&#34;,&#34; ExceptionType&#34;:&#34; Microsoft.Data.OData.ODataException&#34 ;, &#34;堆栈跟踪&#34;:&#34;在System.Web.Http.OData.Routing.DefaultODataPathHandler.ParseAtEntityCollection(IEdmModel model,ODataPathSegment previous,IEdmType previousEdmType,String segment)\ r \ n在System.Web.Http.OData.Routing.DefaultODataPathHandler.Parse(IEdmModel model, 字符串odataPath)\ r \ n在System.Web.Http.OData.Routing.ODataPathRouteConstraint.Match(HttpRequestMessage请求,IHttpRoute路由,String parameterName,IDictionary`2值,HttpRouteDirection routeDirection)&#34;}
附件是我的手表的屏幕截图,显示带有空计数的网址因此转换错误 - 但页面大小是否应自动附加到网址? - 我应该手动完成吗?我在这里遗漏了什么吗?我也尝试过服务器绑定 - 在这种情况下,页面大小=某些东西甚至不起作用 - 所有数据都加载到第一页上。