我知道论坛上还有其他与此相关的问题,但到目前为止发现了有用的解决方案。
我有一个如此定义的控制器:
[HttpPost]
public ActionResult Update(int id, IList<MyObject> data)
{
return Json(new { success = false, message = "saved!" });
}
MyObject
的 Json 数组位于 JsonStore 内,并通过 submitData()
函数调用发送。我可以看到所有内容都正确发送,“data”参数是 MyObject 的数组,如果我手动执行 JSON.Deserialize>>(data)
我得到了我所需要的,这意味着 data 是一个有效的 json 字符串...在标头中我可以看到“application/json”内容类型。
我已经在使用 JsonValueProviderFactory
了,但它没有帮助。根据我的理解,值提供者似乎应该轻松地将数组映射到 IList,所以我想知道我是否做错了什么......
谢谢!
更新
正如一条评论中所述,我的使用场景略有不同:我实际上是通过 Store.submitData() 调用发布此数据...显然,即使标题相似,商店提交也不起作用,因为它实际上生成了一个细绳。
有谁知道如何强制商店执行类似于 JSON.stringify 的操作?
I know there are other questions on the forum regarding this but found ho helpful solution up to now.
I have a controller so defined:
[HttpPost]
public ActionResult Update(int id, IList<MyObject> data)
{
return Json(new { success = false, message = "saved!" });
}
A Json Array of MyObject
is inside a JsonStore and sent up on the submitData()
function call. I can see everything is sent up correctly, the "data" parameter is an array of MyObject, if I manually do JSON.Deserialize<IList<MyObject>>(data)
I get exactly what I need, which means that data is a valid json string... in the Headers I can see the "application/json" content-type.
I am using the JsonValueProviderFactory
already, but it does not help. From my understanding it seems that the value provider should easily map arrays into IList, so I am wondering if I am doing something wrong...
Thanks!
UPDATE
As noted in one comment I have a slightly different use scenario: I am actually posting this data through a Store.submitData() call... apparently, even though the headers are similar, the store submit does not work because it actually generates a string.
Does anyone have any knowledge on how to force the store to do something similar to JSON.stringify?
发布评论
评论(1)
您还没有显示您的客户端代码,但以下内容应该可以正常工作:
它假设
MyObject
的定义如下:但当然它可以是任何复杂的对象。
You haven't shown your client code but the following should work fine:
It assumes that
MyObject
is defined like this:but of course it could be just any complex object.