我怎么能接受我的MVC4应用程序从剑道UI数据源JSON请求? [英] How can I accept JSON requests from a Kendo UI data source in my MVC4 application?

查看:100
本文介绍了我怎么能接受我的MVC4应用程序从剑道UI数据源JSON请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用的是剑道UI格在我MVC3应用程序,并感到相当满意。我使用的是Telerik的提供的示例,摘录如下,以格式化张贴网格的DataSource盟友的数据,一切都很好。不过,我不希望有依靠code这样。我想获得剑道和MVC说话没有翻译,即,该code:

I am using the Kendo UI grid in my MVC3 application and am quite pleased with it. I am using a Telerik provided example, excerpt below, to format the data posted by the grid's DataSource ally, and all is good. However, I don't want to have to rely on code like this. I would like to get Kendo and MVC talking without the 'translator', i.e. this code:

parameterMap: function(data, operation) {
    var result = { };
    for (var i = 0; i < data.models.length; i++) {
        var model = data.models[i];
        for (var member in model) {
            result["models[" + i + "]." + member] = model[member];
        }
    }
    return result;
}

这功能是钩子,让我操纵数据剑道ajaxes出来之前。默认情况下,剑道数据源发送内容类型的形式-CN codeD,但对于MVC模式粘结剂不完全正确。如果没有这一点,我仍然可以使用的FormCollection,做我自己的约束力,但不上。

This function is a 'hook' that allows me to manipulated data before Kendo ajaxes it out. By default, the Kendo DataSource sends content-type form-encoded, but not quite right for the MVC model binder. Without this, I can still use a FormCollection and do my own binding, but that is not on.

当我配置数据源发送JSON和改变我的映射功能,看起来像这样

When I configure the DataSource to send JSON, and change my mapping function to look like this

parameterMap: function(data, operation) {
    return JSON.stringify(data);
}

我得到以下数据是在发送请求,但现在我不知道怎么去MVC绑定到这一点。现在我唯一的希望就是抓住Request.Params [0]操作方法,和反序列化这个JSON自己。

I get the following data being send in the request, but now I have no idea how to get MVC to bind to this. Right now my only hope is to grab Request.Params[0] in the action method, and deserialize this JSON myself.

我不认为我应该写任何code拿到两个HTTP端点在这个时代使用JSON正常通信。我是什么做错了,或者,我应该怎么会在我身边看着,即请求的接收器。我真的preFER以尽量减少对客户端我的干预,也许只是在字符串化电话。

I don't think I should have to write any code to get two HTTP endpoints to communicate properly using JSON in this day and age. What am I doing wrong, or, what should I be looking at on my side, i.e. the receiver of the requests. I would really prefer to minimize my intervention on the client side to maybe just the stringify call.

推荐答案

没有想法,如果这仍是一个问题或没有,因为这是一个相当古老的问题,但我有我在那里JSON数据发运到我的控制器方案我只好给它的名字是什么,这样模型绑定将正常工作,提示:

No idea if this is still a problem or not since this is a rather old question, but I had a scenario where I was shipping up json data to my controller and I had to give it a "hint" on what the name was so that model binding would work correctly:

public JsonResult GetDatByIds([Bind(Prefix="idList[]")]List<Guid> idList)

在我的情况下,剑道被序列化我的数据,并给它一个名称 IDLIST [] 的形式后,而不仅仅是 IDLIST 。有一次,我给它的模型绑定暗示,它的工作就像一个魅力。这可能是你的情况是一样的。

In my scenario, kendo was serializing my data and giving it a name of idList[] in the form post rather than just idList. Once I gave it the model binding hint, it worked like a charm. This might be the same for your scenario.

这篇关于我怎么能接受我的MVC4应用程序从剑道UI数据源JSON请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆