Click here to Skip to main content
15,445,331 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi I want to send my view modal object and two javascript array object in one ajax post

how can I do this please help me.

this is my ajax post
JavaScript
$(document).ready(function() {
    $("#formID").on("submit", function(event) {
        var $this = $(this);
        var frmValues = $this.serialize();
        var myTab = document.getElementById('TB1');
        var Details2 = [];
        var Details = [];
        //LOOP THROUGH EACH ROW OF THE TABLE AFTER HEADER.
        for (i = 1; i < myTab.rows.length; i++) {
            //Details.push([myTab.rows[i].cells[1].children[0].value, myTab.rows[i].cells[2].children[0].value, myTab.rows[i].cells[3].children[0].value]);
            Details.push({ 'Qualification': myTab.rows[i].cells[0].children[0].value, 'PassingYear': myTab.rows[i].cells[1].children[0].value, 'Division': myTab.rows[i].cells[2].children[0].value, 'Percnet': myTab.rows[i].cells[3].children[0].value, 'Institute': myTab.rows[i].cells[4].children[0].value, 'Remark': myTab.rows[i].cells[5].children[0].value })
            //Details2.push({ 'CustomerName': myTab.rows[i].cells[1].children[0].value, 'ProjectName': myTab.rows[i].cells[2].children[0].value, 'ProjectStatus': myTab.rows[i].cells[3].children[0].value })
            Details2.push({ 'Qualification': myTab.rows[i].cells[0].children[0].value, 'PassingYear': myTab.rows[i].cells[1].children[0].value, 'Division': myTab.rows[i].cells[2].children[0].value, 'Percnet': myTab.rows[i].cells[3].children[0].value, 'Institute': myTab.rows[i].cells[4].children[0].value, 'Remark': myTab.rows[i].cells[5].children[0].value })

        }
        $.ajax({
            cache: false,
            async: true,
            type: "POST",
            url: "@Url.Action("Create", "EmpLoyee")",
            data: frmValues,
            data: JSON.stringify(Details),
            data: JSON.stringify(Details2),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            traditional: true,
            success: function(data) {
                alert(data.FirstName);
            }
        });
    });
});

this is form tag
Razor
@using (Html.BeginForm(null,null, FormMethod.Post, new { id = "formID" }))

this is controller
C#
public ActionResult Create(EmployeeDAL OBJ, List<Details> Details, List<Details> Details2)
{

}


What I have tried:

I have tried these two codes
JavaScript
$(function () {
    $("#theButton").click(function (event) {
        event.preventDefault();
        //event.stopImmediatePropagation();
        var $this = $(this);
        var OBJ = $this.serialize();
        var myTab = document.getElementById('TB1');
        var Details2 = [];
        var Details = [];
         //LOOP THROUGH EACH ROW OF THE TABLE AFTER HEADER.
        for (i = 1; i < myTab.rows.length; i++) {
            //Details.push([myTab.rows[i].cells[1].children[0].value, myTab.rows[i].cells[2].children[0].value, myTab.rows[i].cells[3].children[0].value]);
            Details.push({ 'Qualification': myTab.rows[i].cells[0].children[0].value, 'PassingYear': myTab.rows[i].cells[1].children[0].value, 'Division': myTab.rows[i].cells[2].children[0].value, 'Percnet': myTab.rows[i].cells[3].children[0].value, 'Institute': myTab.rows[i].cells[4].children[0].value, 'Remark': myTab.rows[i].cells[5].children[0].value })
            //Details2.push({ 'CustomerName': myTab.rows[i].cells[1].children[0].value, 'ProjectName': myTab.rows[i].cells[2].children[0].value, 'ProjectStatus': myTab.rows[i].cells[3].children[0].value })
            Details2.push({ 'Qualification': myTab.rows[i].cells[0].children[0].value, 'PassingYear': myTab.rows[i].cells[1].children[0].value, 'Division': myTab.rows[i].cells[2].children[0].value, 'Percnet': myTab.rows[i].cells[3].children[0].value, 'Institute': myTab.rows[i].cells[4].children[0].value, 'Remark': myTab.rows[i].cells[5].children[0].value })

        }

        $.ajax({
            type: "POST",
            //traditional: true,
            url: "/EmpLoyee/Create",
            data: JSON.stringify(OBJ),
            data: JSON.stringify(Details),
            data: JSON.stringify(Details2),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            traditional: true,
            success: function (response) {
                alert(response.massge + " record(s) inserted.");
                $("#div").html(response);
                if (response.d == true) {
                    alert("You will now be redirected.");
                    window.location = "//www.aspsnippets.com/";
                }
            }
        });
    })
})
JavaScript
$(document).ready(function() {
    $("#formID").on("submit", function(event) {
        var $this = $(this);
        var frmValues = $this.serialize();
        var myTab = document.getElementById('TB1');
        var Details2 = [];
        var Details = [];
        //LOOP THROUGH EACH ROW OF THE TABLE AFTER HEADER.
        for (i = 1; i < myTab.rows.length; i++) {
            //Details.push([myTab.rows[i].cells[1].children[0].value, myTab.rows[i].cells[2].children[0].value, myTab.rows[i].cells[3].children[0].value]);
            Details.push({ 'Qualification': myTab.rows[i].cells[0].children[0].value, 'PassingYear': myTab.rows[i].cells[1].children[0].value, 'Division': myTab.rows[i].cells[2].children[0].value, 'Percnet': myTab.rows[i].cells[3].children[0].value, 'Institute': myTab.rows[i].cells[4].children[0].value, 'Remark': myTab.rows[i].cells[5].children[0].value })
            //Details2.push({ 'CustomerName': myTab.rows[i].cells[1].children[0].value, 'ProjectName': myTab.rows[i].cells[2].children[0].value, 'ProjectStatus': myTab.rows[i].cells[3].children[0].value })
            Details2.push({ 'Qualification': myTab.rows[i].cells[0].children[0].value, 'PassingYear': myTab.rows[i].cells[1].children[0].value, 'Division': myTab.rows[i].cells[2].children[0].value, 'Percnet': myTab.rows[i].cells[3].children[0].value, 'Institute': myTab.rows[i].cells[4].children[0].value, 'Remark': myTab.rows[i].cells[5].children[0].value })

        }
        $.ajax({
            cache: false,
            async: true,
            type: "POST",
            url: "@Url.Action("Create", "EmpLoyee")",
            data: frmValues,
            data: JSON.stringify(Details),
            data: JSON.stringify(Details2),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            traditional: true,
            success: function(data) {
                alert(data.FirstName);
            }
        });
    });
});
Posted
Updated 29-Sep-20 21:53pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900