0

The issue I am having is that when I am sending an Ajax request, I am getting data, but in Array if I have to look in to the data I have to do data[0]....data[100] I want to convert this data in model so I can pass this to my MVC model or directly pass to my DevExtrem Controller

Jquery

function getPowerSpecialtyId(GirdObject) {
    debugger;
    debugger;
    var BenchMarkId = GirdObject.data ? [GirdObject.data.BenchmarkSurveyId] : null;

    if (BenchMarkId != null) {
        var baseurl = window.location.protocol + "//" + window.location.host;
        var geturl = baseurl + "/Service/Request/BCD?selectedSurveyId=" + BenchMarkId;
        $.ajax({
            contentType: 'application/json; charset=utf-8',
            url: geturl,
            dataType: 'json',
            type: 'GET',
            success: function (data) {
                alert(data);


            },
            error: function (data) {
                DevExpress.ui.dialog.alert("Couldn't fetch details try again", "Oops!");
            }
        });
    }
    else {
        null;
    }
    null;
}

Alert showing this enter image description here

object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[

enter image description here

enter image description here

C# model

  public class BDTO
    {

        public int BId { get; set; }
        public int PId { get; set; }
        public int BkSId { get; set; }      
        public string SName { get; set; }
    }

is it away i can converst everything in Model list so i can get list like?

example List BId: a, PId:s BkSId:2 SName:3 BId: 1a, PId:1s BkSId:22 SName:23

so i can easily pass this to c# model

console.log(data) enter image description here

ZCoder
  • 2,155
  • 5
  • 25
  • 62
  • 1
    This will tell you why you are getting `[object Object]` in your alert: https://stackoverflow.com/questions/4750225/what-does-object-object-mean – Patrick Evans Nov 20 '19 at 20:36
  • 1
    Could you tell us how you'd want the data to look? also, you should output for debuging using `console.log()` – Gijs Beijer Nov 20 '19 at 20:36
  • 1
    Chrome splits them up so as to appear as separate array to make manual traversal easier (I assume), but in reality, all of your elements are in a single array. – isick Nov 20 '19 at 20:38
  • @PatrickEvans Thanks let me check – ZCoder Nov 20 '19 at 20:38
  • @GijsBeijer I need data in List as i have a Model BDTO – ZCoder Nov 20 '19 at 20:39
  • 1
    I think you are getting it in a (js) similar way. Outputting it with an alert will only show you the types of objects, if you'd output the data using `console.log()` you'd see the actual data in your console. – Gijs Beijer Nov 20 '19 at 20:44
  • @GijsBeijer console.log() check the image is it possible we can convert this in a BDTO – ZCoder Nov 20 '19 at 20:48
  • What does BDTO mean? – Barmar Nov 20 '19 at 20:57
  • It's an array of objects, each object has properties `BId`, `PId`, `BkSId`, and `SName`. You can access all those properties using normal object notation, e.g. `data[i].BId`. – Barmar Nov 20 '19 at 20:59
  • Thats exactly what you got there, the browser shows your array in parts (so you can expand them more easily. You should be able to call one of the items as `data[i]` and also the properties using dot notation. so leaves us with what @Barmar says: what does BDTO mean? – Gijs Beijer Nov 20 '19 at 21:24
  • you will have to iterate over it and then pass it back to the service as an object –  Nov 21 '19 at 16:21
  • or an array of objects –  Nov 21 '19 at 16:21

0 Answers0