我正在尝试以下操作:内部带有字典的模型在第一个ajax请求上发送该模型,然后将结果再次序列化,然后将其发送回 Controller 。
这应该测试我可以在模型中找回字典。没用
这是我的简单测试:
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是相同的。我只能假设有些东西在途中迷路了。
有人知道我在做什么错吗?
最佳答案
由于实现了JsonValueProviderFactory的方式,不支持绑定(bind)字典。
关于c# - POST json字典,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4710729/