How to treat an array with N rows and transform to a list to send to C #

0

I'm sending an array of the angular js to the controller of C # , and I'm handling it with stringfy for json in>.

In my method POST it does not receive anything, it simply returns null

C # code

 public void Post(string values)
    {
        var r = values;

    }

Javascript Code

    $scope.SubmitData = function (DataToSubmit) {
    var string = JSON.stringify(DataToSubmit);
    $http({
        method: 'POST',
        data: {
            values: string,
        },
        url: 'api/aulamethod',
    });
}

Date inserted into inserts

Datathatappearsinvarstringafterstringfy

values:"[{"CompanyName":"column a","SupplierCode":"column b","DocumentNumber":"column c","Reference":"column d","InternalCurrencyValue":"column e","BlockadeUnblocking1":"column f","Justification":"column g","Request":"column h","$$hashKey":"object:23"}]"
    
asked by anonymous 10.08.2018 / 18:34

1 answer

1

If your goal is to post this value as String , you must first ensure that you are performing your post with the type in application/json .

Create a ViewModel to reflect the structure you are posting:

public class ValuesViewModel
{
    public string Values { get; set; }
}

And in the controller do not forget to add [FromBody]

[HttpPost]
public void Post([FromBody]ValuesViewModel values)
{ 
   var r = values;       
}
    
10.08.2018 / 20:50