Я пытаюсь сделать следующее: Модель со встроенным словарем отправляет ее по первому запросу 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 идентичны. Я могу только предположить, что на пути что-то потеряется.
У кого-нибудь есть идея, что я делаю неправильно?