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(); }
data: model. There is nothing to translate into the string here either Or if the parameter should be named, thendata : {'model' : model}- teran