Designing data in $.ajax to match server side model definition

后端 未结 1 1974
予麋鹿
予麋鹿 2020-12-22 10:18

I\'m running the following AJAX call.

var submission = {};
submission.input = [];
submission.input.push({ Id: "{ab684cb0-a5a4-4158-ac07-adff49c0c30f}&quo         


        
相关标签:
1条回答
  • 2020-12-22 10:30

    You should be able to simplify the jquery. With what you have here you don't need the submission. If you are sending a complex list back to the controller you need to name your variables but since you are just sending a string back you don't need to do that. Try changing your data to

    var input = [];
    input.push("{ab684cb0-a5a4-4158-ac07-adff49c0c30f}");
    input.push("{bb684cb0-a5a4-4158-ac07-adff49c0c30f}");
    

    then in the ajax call

    data: input,
    

    or

    data: Json.stringify(input);
    

    then on your controller

    public ActionResult Action(List<String> input){...
    

    Edit:

    try changing your jquery to this:

    var stuff= {};
    stuff.Id = "{cb684cb0-a5a4-4158-ac07-adff49c0c30f}";
    stuff.Ids= [];
    stuff.Ids.push("{ab684cb0-a5a4-4158-ac07-adff49c0c30f}");
    stuff.Ids.push("{bb684cb0-a5a4-4158-ac07-adff49c0c30f}");
    

    then in your ajax have data: stuff, or data: Json.stringify(stuff),

    0 讨论(0)
提交回复
热议问题