我目前有一堆方法在我的控制器从表行中选择记录。ASP.NET MVC将映射对象数组传递给控制器参数从jQuery
,所以我可能有类似
var ids = [];
var prices = [];
var customers = [];
$selectedRow.each(function() {
ids.push($(this).find('.id').text());
prices.push($(this).find('.price').text());
customers.push($(this).find('.customer').text());
});
$.post(....) // AJAX call to controller method
和Controller我结束了
public ActionResult DoSomething(int[] ids, double[] prices, string[] customers) { ... }
这仅仅是一个有点乱来处理使用迭代器。
我真正喜欢的是有
Class Foo
{
int id;
double price;
string customer;
}
,并能够接收
public ActionResult DoSomething(List<Foo> foos) { ... }
这可能吗?
虽然我没有尝试将模型绑定到表单,但这些解决方案不会与jQuery提交的值一起工作吗? – fearofawhackplanet 2010-11-23 16:49:02
是的,如果你使用`(“#form”)。serialize()`时提交表单本身 – Lorenzo 2010-11-23 16:51:12