模型绑定到列表>>发布 JavaScript 数据对象时
我正在尝试发布一个 JavaScript 数据对象,其中包含以下内容:
$.post(frm.attr("action"), data, function(res)
{
// do some stuff
}, "json");
其中“数据”采用的结构是“
data
- panelId
- siteId
- ConfiguredFactsheetId // this is an array of CheckBox ids that correspond to ConfiguredFactsheets
- 123
- 234
- 345
通过此,站点和站点”。面板已正确实例化并且与其数据绑定,但 List 对象为 null。
public JsonResult Edit(Site site, Panel panel, List<ConfiguredFactsheet> configuredFactsheets)
{
// do stuff
return Json(success);
}
现在,我意识到我的“数据”对象的ConfiguredFactsheetId 属性只是一个id 值数组。我是否需要指定每个值对应于我的ConfiguredFactsheet 对象的configuredFactsheetId 属性?如果是这样,我的数据对象将采用类似于的形式,
data
- panelId
- siteId
- ConfiguredFactsheet // this is an array of CheckBox ids that correspond to ConfiguredFactsheets
- ConfiguredFactsheetId:123
- ConfiguredFactsheetId:234
- ConfiguredFactsheetId:345
但这显然行不通,因为每次我向对象添加新的ConfiguredFactsheetId 时,它都会覆盖前一个。
我知道如果我构建了一个表单的查询字符串,我可以做到这一点
"&ConfiguredFactsheet[i].configuredFactsheetId = " + configuredFactsheetId;
,但我想将所有内容包含在一个数据对象中 有
什么建议吗?我需要更清楚地解释任何事情(可能是所有事情!)吗?
谢谢
戴夫
I'm trying to post a JavaScript data object with the following:
$.post(frm.attr("action"), data, function(res)
{
// do some stuff
}, "json");
where 'data' takes the structure of
data
- panelId
- siteId
- ConfiguredFactsheetId // this is an array of CheckBox ids that correspond to ConfiguredFactsheets
- 123
- 234
- 345
With this, both site & panel are correctly instantiated & bound with their data but the List object is null.
public JsonResult Edit(Site site, Panel panel, List<ConfiguredFactsheet> configuredFactsheets)
{
// do stuff
return Json(success);
}
Now, I realise that my 'data' object's ConfiguredFactsheetId property is just an array of id values. Do I need to specify that each value corresponds to a configuredFactsheetId property of my ConfiguredFactsheet object? If so, my data object would take a form similart to
data
- panelId
- siteId
- ConfiguredFactsheet // this is an array of CheckBox ids that correspond to ConfiguredFactsheets
- ConfiguredFactsheetId:123
- ConfiguredFactsheetId:234
- ConfiguredFactsheetId:345
but this obviously won't work because every time I add a new ConfiguredFactsheetId to the object, it'll just overwrite the previous one.
I know I can do this if I built a query string of the form
"&ConfiguredFactsheet[i].configuredFactsheetId = " + configuredFactsheetId;
but I'd like to contain everything in a single data object
Any suggestions? Do I need to explain anything (probably everything!) more clearly?
Thanks
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后,这有效:
注意:阅读 $.getAttributes
In the end, this worked:
Note: read about $.getAttributes
另一种方法是发布:
并接受它作为 IEnumerable
An alternative is to post:
And accept it as an IEnumerable