How do I make an array of objects in ASP.NET C #

0

I've already tried everything. Someone who could help me

That's how I send my object to the controller

$.ajax({
        type: "GET",
        url: "@Url.Action("editarTarjetaCapacitacion", 
        "TarjetaCapacitacion")",

        scriptCharset: "utf-8",
        dataType: "json",
        contentType: "appliction/json; charset=iso-8859-1",
        data: {
            InstructoresExternos: JSON.stringify(tarjetaCapacitacion.InstructoresExternos)
        },
        success: function (respuesta) {
            if (respuesta.errorCode != 200) {
                ErrorBottom(respuesta.mensajeError);
                return;
            }
            window.location.replace("http://" + window.location.host + "@Url.Action("Index", "TarjetaCapacitacion")");
        }

This is where I receive it

public JsonObject editarTarjetaCapacitacion(string[] InstructoresExternos)
   {}

What I'm trying to do is get the fix and go through it but I can not make the fix

    
asked by Programador S 21.06.2018 в 20:49
source

1 answer

0

What I do is that in the JSON.stringify I direct the Array. Something like that

data: JSON.stringify{parametro: NombreDelArray}

By the time I receive the Array on the Server, what I do is that I have a class that contains the data I request from the Array. That is to say that if in the Array I send data such as height, name and age I have a class called Person and person is as follows.

class Persona{
public string Altura {get; set;}
//etc
}

and in your method I collect the Array as:

public GetPersona(Persona p) {//.... }

Instead of a string[] I save the data in the class and then to access them I only type p.Height, p.Name, etc.

I hope you help

    
answered by 21.06.2018 в 21:24