passing array from javascript to controller MVC 4

前端 未结 4 1357
抹茶落季
抹茶落季 2021-01-22 23:19

I am using razor and I\'m having a hard time passing an array to a controller. the array contains objects that I made and I am trying to do this:

$.ajax({
     t         


        
4条回答
  •  离开以前
    2021-01-22 23:42

    Client side:

    $.ajax({
         type: "POST",
         url: "HomePage/HandleOperations",
         data: {operations: operationCollection},
         success: function (data) { alert("SUCCESS"); }
    });
    

    and declare a class server side like this:

    public class Operation
    {
      public int Index;
      public string Source;
      public string Target;
      public int AddOrDel;
    }
    

    then you can have this action:

    public void HandleOperations(Operation[] operations)
    {
    }
    

提交回复
热议问题