在kendoUI请求期间,AJAX网格使用HttpGet请求来更新数据。(http://www.kendoui.com/documentation/asp-net-mvc/helpers/grid/ajax-binding.aspx)服务器返回一个Json结果,为了让它正常工作,我们需要使用以下代码:
return Json(Result, JsonRequestBehavior.AllowGet);这项工作做得很好,但这是一个安全漏洞(这就是为什么微软让我们把"AllowGet“放在里面)。
返回Json的安全方法是在HttpPost中,但是kendoui网格不允许这样做。
我想使用kendoui网格。有没有一种方法可以使用HttpGet,返回Json,并安全地执行?
谢谢!
发布于 2012-07-18 18:19:26
如果您使用的是Kendo Grid的MVC包装器,则不会发生这种情况。由于这种ASP.NET MVC行为,网格被配置为发出POST请求。不过,请确保您包含了kendo.aspnetmvc.min.js。更多信息可以在docs中找到。
发布于 2012-07-18 08:04:30
在使用ajax时,kendo数据源默认使用GET,但是可以通过定义post的传输设置来使用POST。
下面是使用post的Telerik kendo CRUD example中的代码的简短版本。
<script>
$(function () {
$("#grid").kendoGrid({
toolbar: ["create", "save", "cancel"],
dataSource: {
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
UnitPrice: { type: "number", validation: { required: true } }
}
}
},
transport: {
create: {
url: "Products.svc/Create",
contentType: "application/json; charset=utf-8",
type: "POST"
},
read: {
url: "Products.svc/Read",
contentType: "application/json; charset=utf-8",
type: "POST"
},
parameterMap: function(data, operation) {
if (operation != "read") {
return JSON.stringify({ products: data.models })
}
}
}
}
});
});
</script>https://stackoverflow.com/questions/11531416
复制相似问题