It's possible to build an array in jquery/javascript to send it to my controller c# ?
I get a list of employes from a select multiple, i can alert them like this :
<div class="demo">
<select style="display:none" id="liste" multiple="" placeholder="Select">
@foreach (var employe in ViewBag.Employes)
{
<option value="@employe.ID_Employe">@employe.Name</option>
}
</select>
</div>
<a class="btn btn-default" id="check" href="#">Suivant</a>
My script :
$('#check').on('click', function () {
$("#liste").find("option:selected").each(function () { alert($(this).text()); });
});
I send data like this :
$.ajax({
type: 'POST',
dataType: 'json',
url: '/MyAjaxRoute',
data: { arraytosend: arraybuildInJS },
success: function (response) {
if (response.success) {
alert('yes');
}
},
- Can you explain me how to make an array in js and to receive it in a c# mvc controller ?