Home > database >  I'm trying To Send Array with Serialize Form as a parameter from ajax to controller but the sec
I'm trying To Send Array with Serialize Form as a parameter from ajax to controller but the sec

Time:02-21

$("#CreateDepartmentForm").submit(function (e) { e.preventDefault();

        var modelx = $(this).serialize();
        console.log(modelx);
        var cars = [
            {
                "color": "purple",
                "type": "minivan",
                "registration": "2018-03-03",
                "capacity": 7
            },
            {
                "color": "red",
                "type": "station wagon",
                "registration": "2018-03-03",
                "capacity": 20
            }];
       
        $.ajax({
            type: "POST",
            url: "/Department/CreateDepartmentByAjax",
            data: modelx   "&test="   cars,
            success: function (res) {
            },
         });

public IActionResult CreateDepartmentByAjax(DepartmentVM model,List<cars> test)
    {
     }

   public  class cars
{
    public string color  { get; set; }
    public string type { get; set; }
    public string registration { get; set; }
    public int capacity { get; set; }
}

Request Payload

Visual Studio Debugging Output

Visual Studio Debugging Output

  • Related