我目前有一堆方法在我的控制器從錶行中選擇記錄。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