Is it possible to create an array in jQuery/JavaScript and then send it to my C# controller?
I have a list of employees from a select multiple, which I can display 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="#">Next</a>
Here is my script :
$('#check').on('click', function () {
$("#liste").find("option:selected").each(function () { alert($(this).text()); });
});
To send the data, I use the following code :
$.ajax({
type: 'POST',
dataType: 'json',
url: '/MyAjaxRoute',
data: { arraytosend: arraybuildInJS },
success: function (response) {
if (response.success) {
alert('yes');
}
},
- Could you please explain to me how to create an array in JavaScript and pass it to a C# MVC controller?