You must Sign In to post a response.
  • Category: ASP.Net MVC

    Bind webgrid with webapi json

    how to bind data to webgrid

    function () {
    var id = "4";

    url: 'http://localhost:17026/api/Hotelcheck?rating' + id,
    type: 'GET',
    dataType: "json",
    success: function (data) {

    $.each(data, function (i, v) {
    $('#result').html($('#result').html() + v.HotelCode + '<br />');
    // debugger;

    var datavalue = data;
    var myJsonObject = datavalue;

    var CarModel = myJsonObject[0].HotelCode;
    var CarName = myJsonObject[0].HotelsName;
    var CarColor = myJsonObject[0].Location;

    // alert(t + t1);
    error: function (msg) { alert(msg); }
  • #766928
    According to your code you are performing initial data load via ajax but you can't do that because webgrid is not designed for that. Alternatively you can pass the initial data via a model and then do updates over ajax,

    You can find the sample code which demonstrates how to bind igGrid to WebAPI where Grid requests the data in JSON format using an Ajax call over here:

    Also find sample over here:

    Or you can use PartialView to bind Data to Web grid

  • #766929
    You can make simple HTTP call to your web api. You can get generic collection list from the web api. Once you get the data you can assign the data souce into your grid view and do the data binding. Following is the sample http call to get the data from the web API. In the following code. You can send you input based on your requirement. In your case you should send the JSON string. If you want you can get the JSON/Generic collection.

    using (var Myclient = new HttpClient())
    Myclient.BaseAddress = new Uri("http://localhost/AppName/");
    Myclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    HttpResponseMessage Myresponse = await client.GetAsync("webapi/Items");
    if (Myresponse.IsSuccessStatusCode)
    List<Item> MyItem = await response.Content.ReadAsAsync>List<Item>>();
    // Assign the data source in to your grid view.

    By Nathan
    Direction is important than speed

  • Sign In to post your comments