我做了一些工作在.NET 4中,MVC 3和jQuery V1.5动态传递JSON对象到C#MVC控制器
我有一个JSON对象,可根据其网页呼吁改变它。我想将对象传递给控制器。
{ id: 1, title: "Some text", category: "test" }
我明白,如果我创建一个自定义模式,如
[Serializable]
public class myObject
{
public int id { get; set; }
public string title { get; set; }
public string category { get; set; }
}
,并在我的控制器使用这个功能,比如
public void DoSomething(myObject data)
{
// do something
}
和使用jQuery的阿贾克斯方法一样传递对象这个:
$.ajax({
type: "POST",
url: "/controller/method",
myjsonobject,
dataType: "json",
traditional: true
});
这工作正常,我的JSON对象映射到我的C#对象。我想要做的是通过一个可能会改变的JSON对象。当它发生变化时,我不希望每次JSON对象更改时都要将项目添加到我的C#模型中。
这实际上可行吗?我试图将对象映射到字典,但数据的值将最终为空。
感谢
相关的/欺骗:http://stackoverflow.com/questions/5473156/how-to-get-a-dynamically-created-json-data -set-in-mvc-3-控制器 http://stackoverflow.com/questions/10787679/passing-unstructured-json-between-jquery-and-mvc-controller-actions – 2013-01-07 10:14:33