3
I have this function with array and I’m not getting through to the controller values, i listing, it appears correctly, use angular.
$scope.addItem = function (user) {
$scope.items.push({
de: $scope.total,
ate: user.ate,
tipo: user.tipo,
valor: user.valor,
});
$scope.total = ''
$scope.total = user.ate;
user.ate = '';
user.tipo = '';
user.valor = '';
};
$scope.gravaItem = function () {
$.ajax({
type: 'GET',
url: '/TaxaPreco/SalvarItens',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify($scope.items),
success: function (result) {
console.log('Data received: ');
console.log(result);
}
})
};
And here are the results when I give one console.log($scope.items)
;
Array(1)
0
:
{de: "00:01", ate: "00:29", tipo: "0", valor: "5", $$hashKey: "object:3"}
How can I pass these values on to the controller? And here’s how I’m trying to get controller, but in any case, none worked as it should:
public async Task<ActionResult> SalvarItens(List<TarifasPrecosItens> nome )
{
var item = new TarifasPrecosItens()
{
De = nome[0].De,
//De = itens.De,
//Ate = itens.Ate,
//Fracao = itens.,
//RepetirACada = 0,
//TipoValor = tipovalor,
//Valor = valor,
//TarifasPrecosId = 25,
};
Doubt: if
nome
is a list ofTarifasPrecosItens
, then why create another objectTarifasPrecosItens
with the data? It would not be enough to do something likevar item = nome[0]
?– Woss
I need it to receive the array to perform the Inserts on the controller page, and this is not happening.
– Mariana
I updated the question with the angle that picks up the data, so you can understand better.
– Mariana