-3
I was able to send the values of a checkbox to the controller using the function below:
function InformacoesAdicionais() {
var listOfRegiao = [];
$.each($("#select-regiao option:selected"),
function (index, data) {
listOfRegiao.push($(this).val());
});
$.ajax(
{
async: true,
dataType: 'JSON',
type: 'POST',
url: '/Campanha/InformacoesAdicionais',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ listOfRegiao: listOfRegiao }),
success: function (data) {
if (data.Success) {
}
},
error: function () {
alert("Ocorreu um erro ao salvar os dados, tente novamente.")
},
});
}
<select id="select-regiao" multiple="multiple">
<option value="Capital">Capital</option>
<option value="Interior">Interior</option>
<option value="Vale">Vale</option>
<option value="Litoral">Litoral</option>
</select>
However, I need to send the values of another checkbox in the same function simultaneously. I tried several ways but always sends only the value of the checkbox "select-regiao" while the other is null.
Second checkbox:
<select id="select-canal" multiple="multiple">
<option value="Farma">Farma</option>
<option value="Perfumaria">Perfumaria</option>
<option value="Alimentar">Alimentar</option>
</select>
Here
data: JSON.stringify({ listOfRegiao: listOfRegiao })
you are only sending a select. Not to mention that there is no checkbox in the code.– Sam
I am using Jquery Multiple to create checkboxes in the view. When the user marks one or more values from the list, the function collects the name of the fields and creates an array of values.
– phlr