Hello, please help with the code. I want to send an array through ajax and process it in the controller, but the array comes up empty. Where can there be a mistake?

Script

<script> var model = @Html.Raw(Json.Encode(Model.Values)); $("#nextbtn").click("on", function () { $.ajax( { url: '/api/Channel', type: 'POST', contentType: 'application/json', data: { '':JSON.stringify(model) }, success: function(result) { $("#results").html(result); } } ); } ); 

Piece of page markup

 @model IDictionary<int, Applience> <button type="submit" name="action" value="Next" class="btn btn-primary" id="nextbtn">-></button> <br /> <div id="results"></div> 

api controller

 public string PostNext(List<Applience> model) { IChannel tv= model.FirstOrDefault(m => m is IChannel) as IChannel; tv.NextChannel(); return tv.ToString(); } 
  • you kind of want to send an array, why do you cram it into an object, with some empty key at the same time. just data: model . There is nothing to translate into the string here either Or if the parameter should be named, then data : {'model' : model} - teran
  • @teran, I tried many options how to pass an array (with a key as a parameter in the controller, without translation into a string) and not one did not work. Can you tell me how to do it right? - Nameless
  • try to check with this manual metanit.com/sharp/aspnet_webapi/2.7.php - teran

0