0
votes

I have a controller method like this:

[GET]
public ActionResult GetFailureInfo(List<FailureInfoModel> failureInfoModels){}

And I have a model like this:

public class FailureInfoModel {
      public int Id {get; set;}
      public List<string> Reasons {get; set;}
}

Now I would like to pass json data by using window.open() in frontend like this:

<script type="text/javascript">
    var json = 
        [
            {
                Id:111,
                Reasons:[1,2]
            }
        ];
    var formatJson = JSON.stringify({failureInfoModels : json});
    
    window.open("url?failureInfoModels=" + escape(formatJson))
</script>

But there can only get a object of List with 0 items. How should I change my code to work this out? Thanks.

1
At least one problem is that your Reasons array has numbers instead of strings - Crowcoder

1 Answers

0
votes

Change input to string and Deserialize it.

1. public ActionResult GetFailureInfo(string failureInfoModels = "")  
        {  
2.  List<FailureInfoModel> failuresData = JsonConvert.DeserializeObject<List<FailureInfoModel>>(failureInfoModels);  

}