POST JSON字典 [英] POST json dictionary

查看:152
本文介绍了POST JSON字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以下几点:借助字典的模型里面把它的第一个Ajax请求再取结果再次序列化,并将其发送给控制器。

I'm trying the following : A model with a dictionary inside send it on the first ajax request then take the result serialize it again and send it back to the controller.

这应该测试我能回到我的模型字典。它不工作

This should test that I can get back a dictionary in my model. It doesn't work

下面是我简单的测试:

public class HomeController : Controller
{
    public ActionResult Index (T a)
    {
      return View();
    }

    public JsonResult A(T t)
    {
      if (t.Name.IsEmpty())
      {
        t = new T();
        t.Name = "myname";
        t.D = new Dictionary<string, string>();
        t.D.Add("a", "a");
        t.D.Add("b", "b");
        t.D.Add("c", "c");
      }
      return Json(t);
    }
}

//model
public class T
{
  public string Name { get; set; }
  public IDictionary<string,string> D { get; set; }
}

JavaScript的:

The javascript:

$(function () {
    var o = {
        Name: 'somename',
        "D": {
            "a": "b",
            "b": "c",
            "c": "d"
        }
    };

    $.ajax({
        url: actionUrl('/home/a'),
        contentType: 'application/json',
        type: 'POST',
        success: function (result) {
            $.ajax({
                url: actionUrl('/home/a'),
                data: JSON.stringify(result),
                contentType: 'application/json',
                type: 'POST',
                success: function (result) {
                }
            });
        }
    });
});

在萤火json的接收和发送的JSON是相同的。我只能假设东西丢失在路上。

In firebug the json received and the json sent are identical. I can only assume something gets lost on the way.

任何人有一个想法是什么,我做错了吗?

Anyone has an idea as to what I'm doing wrong?

推荐答案

由于路<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.mvc.jsonvalueproviderfactory.aspx\">JsonValueProviderFactory实现绑定字典不支持。

Due to the way JsonValueProviderFactory is implemented binding dictionaries is not supported.

这篇关于POST JSON字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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