There is known trouble with sending array to ASP.NET MVC controller. I've found a lot of solutions like that. Why don't use usual object instead array? It works good. Example of code:
<script>
$(function(){
$('.asArray').click(function(){
var array = Array();
array[0] = 'Dima';
array[1] = 'Ann';
array[2] = 'John';
$.post('/Home/Get', {data: array}, function(data){alert(data);});
});
$('.asObject').click(function(){ // works good
var array = Object();
array[0] = 'Dima';
array[1] = 'Ann';
array[2] = 'John';
$.post('/Home/Get', {data: array}, function(data){alert(data);});
});
});
</script>
<div>
<input type="button" class="asArray" value="asArray"/>
<input type="button" class="asObject" va开发者_JAVA技巧lue="asObject"/>
controller action:
public ActionResult Get(IEnumerable<string> data)
{
if (data == null)
return Content("data == null");
return Content("data = [" + data.Aggregate((agr, curr) => agr + ", " + curr) + "]");
}
精彩评论