Submission of Form and Data from Table to ASP .NET Controller by AJAX

1

This is my first question on this platform. I am new with the ASP .NET framework and I have a problem that I tell you:

I have a table that is generated as products are added to it to be billed. I also have a form with the data of the invoice.

I need to send them to the controller to be processed.

a class that contains the products that are in the "ProdutosT" table, another that receives the data from the DatosF invoice. and Finally a class that receives an DatosF object and a list of ProductosT.

The problem is that I can not make the two elements arrive, the form of the data and the products to the controller

//clases
    public class ProductoT
    {
        public string codigo { get; set; }
        public float cantidad { get; set; }
        public float precio { get; set; }
    }

public class DatosF { public string Fecha { get; set; } public string Cliente { get; set; } public string TipoPago { get; set; } public string PrecioSelect { get; set; } public string DiasCredito { get; set; } public string Vendedor { get; set; } public string PrecioEditable { get; set; } public string Observacion { get; set; } } public class FaturaPuntoV { public DatosF datosF { get; set; } public List productosF { get; set; } }

//Javascript $(".pagar").click(function () { var TableData = new Array();

$('#tabla_productoF tr').each(function (row, tr) { TableData[row] = { "codigo": $(tr).find('td:eq(2)').text() , "cantidad": $(tr).find('td .cantidadProducto').val() , "precio": $(tr).find('td .precioItemN').val() } }); (function ($) { $.fn.serializeFormJSON = function () { var o = {}; var a = this.serializeArray(); $.each(a, function () { if (o[this.name]) { if (!o[this.name].push) { o[this.name] = [o[this.name]]; } o[this.name].push(this.value || ''); } else { o[this.name] = this.value || ''; } }); return o; }; })(jQuery); y = new Array(); var i = $("#FormularioFactura").serializeFormJSON(); y.push({ DatosF: i }); y.push({ ProductosT: TableData }); console.log(JSON.stringify(y)); $.ajax({ url: 'FacturacionPuntoV/Create', type: 'POST', dataType: 'json', traditional: true, contentType: "application/json,utf-8", data: JSON.stringify(y), async: true, cache: false, beforeSend: function (result) { }, success: function (result) {

    
asked by Manuel Rangel 05.09.2018 в 16:08
source

0 answers