【发布时间】:2011-01-17 06:56:50
【问题描述】:
我正在尝试以下操作:内部带有字典的模型在第一个 ajax 请求上发送它,然后将结果再次序列化并将其发送回控制器。
这应该测试我可以在我的模型中取回字典。它不起作用
这是我的简单测试:
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:
$(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) {
}
});
}
});
});
在 firebug 中接收到的 json 和发送的 json 是相同的。我只能假设有些东西在途中丢失了。
有人知道我做错了什么吗?
【问题讨论】:
标签: c# json asp.net-mvc-3 post dictionary