Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.Net MVC : Send an array in POST

ASP.Net MVC : Send an array in POST

Scheduled Pinned Locked Moved Web Development
asp-netcsharpdata-structuresjsonarchitecture
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hageshii
    wrote on last edited by
    #1

    hello, On my site in ASP.Net MVC, I try to send the contents of an array in a function using a POST but nothing happens and I don't understand why. My class :

    public class AdresseIP
    {
    public int? Idclient { get; set; }
    public int? ip1 { get; set; }
    public int? ip2 { get; set; }
    public int? ip3 { get; set; }
    public int? ip4 { get; set; }
    public int? idplan { get; set; }
    }

    My function (empty for the moment):

    [HttpPost]
    public ActionResult MAJIP(IEnumerable lst)

    {
    
    
        return View(1);
    }
    

    The method I use to send the array from my page:

    function Valider(tableID) {
    console.log("test " + tableID);
    var IPs = new Array();
    $("#" + tableID + " TBODY TR").each(function () {
    var row = $(this);
    var IP = {};
    IP.Idclient = row.find("TD").eq(0).text();
    IP.idplan = row.find("TD").eq(1).text();
    IP.ip1 = row.find("TD").eq(2).text();
    IP.ip2 = row.find("TD").eq(3).text();
    IP.ip3 = row.find("TD").eq(4).text();
    IP.ip4 = row.find("TD").eq(5).text();
    IPs.push(IP);

    });
    

    console.log(JSON.parse(JSON.stringify(IPs)));
    IPs2 = JSON.parse(JSON.stringify(IPs));
    console.log(IPs2);

        $.ajax({
            type: "POST",
            url: "/IP/MAJIP/",
            data: IPs2,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (r) {
                alert(r);
                if (r == 1) {
                    console.log('test1 ' + r)
                } else {
                    console.log('test2 ' + r);
                }
    
            }
        });
    

    }

    The console.log(IPs); displays the contents of the array correctly. There may be better methods, but I don't know of any. When I validate, my function receives a Null. Yet all my console.log(IPs); return the expected value. So here I don't know. Any idea please?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups