KendoUI网格MVC包装和网页API [英] KendoUI Grid with MVC Wrappers and Web API
问题描述
我使用的是与ASP.Net MVC封装器剑道UI电网。我的网格数据源定义如下:
I'm using Kendo UI grid with ASP.Net MVC Wrappers. My grid datasource is defined as follows:
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(p => p.Code);
})
.Read(read => read.Url("api/ProjectMilestone").Type(HttpVerbs.Get))
.Create(create => create.Url("api/ProjectMilestone").Type(HttpVerbs.Post))
.Update(update => update.Url("api/ProjectMilestone").Type(HttpVerbs.Put))
.Destroy(destroy => destroy.Url("api/ProjectMilestone").Type(HttpVerbs.Delete))
)
所以,人们所期望的GET URL将作为生成[服务器] / [应用] / API / ProjectMilestone
。
但在我的情况下,对其中的网格托管的网页是在以下网址: [服务器] / [应用] /项目
。
这将导致生成的的GET网址[服务器] / [应用] /项目/ API / ProjectMilestone
,当然服务器返回错误404没有找到。
But in my case, the page on which the grid is hosted is at the following URL: [server]/[app]/Project
.
This results in the GET url being generated as [server]/[app]/Project/api/ProjectMilestone
, and of course the server returns error 404 not found.
请告诉我,我怎么能有作为生成此网址[服务器] / [应用] / API / ProjectMilestone
代替。
Please tell me how I can have the GET url generated as [server]/[app]/api/ProjectMilestone
instead.
推荐答案
原来,正确的做法是定义数据源如下:
Turns out the correct approach is to define the datasource as follows:
.Read(read => read.Url(Url.RouteUrl("DefaultApi", new { httproute ="", controller="ProjectMilestone" })).Type(HttpVerbs.Get))
.Create(create => create.Url(Url.RouteUrl("DefaultApi", new { httproute ="", controller="ProjectMilestone" })).Type(HttpVerbs.Post))
.Update(update => update.Url(Url.RouteUrl("DefaultApi", new { httproute ="", controller="ProjectMilestone" })).Type(HttpVerbs.Put))
.Destroy(destroy => destroy.Url(Url.RouteUrl("DefaultApi", new { httproute ="", controller="ProjectMilestone" })).Type(HttpVerbs.Delete))
从采取这一回答。
这篇关于KendoUI网格MVC包装和网页API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!