0

I have a number of hidden input elements on my ASP.NET MVC page. They each hold an integer value. They are identified by $('table#ratings input[name=newReviewRatings]').

Is it possible to post the integers in those hidden input elements using $.post() so that the controller is passed an array of integers?

This is probably easier using a <form> element and simply posting the form. But is it possible to do it using jQuery?

4

2 回答 2

2

适合这种情况的理想方法是使用map如下:

var data = $('#ratings input[name=newReviewRatings]').map(function(){
    return $(this).val();
}).get();

// Post the data to the respective url
$.post(your_url, data);

.map()方法对于获取或设置元素集合的值特别有用。

于 2013-07-16T04:46:25.187 回答
2

你应该能够使用这样的东西来获取你的数组。

var data = [];
$('table#ratings input[name=newReviewRatings]').each(function(){
    data.push($(this).val());
});
$.post(url, data);
于 2013-07-16T04:34:14.857 回答