How do I get a list of JS objects in Controller C # MVC?

1

I have an object with a list that will return me 3 or more items. I pass this object like this:

 var jsonObjs = JSON.stringify(arrayObj);     
  alert(jsonObjs);      
  CarregaNotas(jsonObjs);

functionCarregaNotas(notas){jQuery.ajax({type:"POST",
                    url: "/Expedicao/Minuta/GeraNotas",
                    dataType: "json",
                    data: notas,
                    success: function (data) {


                        }

                    });
                }
            });
        }

How to get this list in the controller and pass or sweep in the Model? For each item I will have to add an "And" or "In" in the "Select"

    
asked by anonymous 30.04.2018 / 14:40

1 answer

1

First you create a class with the same properties as the one you are passing in JSON.

public class Obj
{
    public int Quantidade { get; set; }
    public string Doc { get; set; }
    public string Serie { get; set; }
}

In the controller you get the stringJson and convert it to a list of this object.

var listaConvertida = JsonConvert.DeserializeObject<List<Obj>>(stringJson);

To use the JsonConvert class, you must have the NuGet Newtonsoft.Json package installed.

    
04.05.2018 / 22:05