Results 1 to 4 of 4

Thread: C# Data exchange using JSON

  1. #1
    Sencha User
    Join Date
    Apr 2017
    Posts
    3
    Vote Rating
    1
      1  

    Default C# Data exchange using JSON

    HI,

    I'm using Ext JS 6.2 with a C# backend and trying to get data from my database in a grid. So far I got the entity framework setting up a database connection and using Linq I got my data. After parsing the result with javascriptserializer I got the json result to send to my ext frontend. It all works, the ajax call returns the data to the store, but the grid stays blank.

    my c# controller

    public ActionResult Index()
    {
    var context = new Database_Entities();
    var table = (from Table in context.Table select Table).Take(1);
    return Json(new JavaScriptSerializer().Serialize(new { Table = table }), JsonRequestBehavior.AllowGet);
    }

    the result

    "{"Table":[{"ID":1,"strType":"ALL","lngParentID":null,"strHierarchy":"\\\\1\\\","lngExpanded":null,"lngIsFolder":null,"lngLevel":0,"strFullHierarchy":"\\\\ALL\\\","lngChildCount":8,"lngDurationPossible":1}"

    the store

    Ext.define('ExtExampleApplication.store.Table', {
    extend: 'Ext.data.Store',
    alias: 'store.table',
    model: 'ExtExampleApplication.model.Table',
    proxy: {
    type: 'ajax',
    url: '/Home',
    reader: { type: 'json', rootProperty: 'Table'}
    },
    autoLoad: true
    });

    It all looks pretty straight forward, but no result in my ext app. What am I missing here? Is my problem the escaped Json and do I need a transform in my store?

    Could somebody give me some pointers?

    Thanks in advance.

  2. #2
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506
    Vote Rating
    292
      1  

    Default

    Any errors or warnings in the console? Your JSON data seems to be incomplete (no closing square and curly brace). Also this may just be how you represented it here, but your JSON is enclosed entirely within double quotes which is not valid.

  3. #3
    Sencha User
    Join Date
    Jun 2017
    Location
    United States
    Posts
    1
    Vote Rating
    0
      0  

    Default

    Please check for the errors and warnings. You've missed bracket and curly braces... this is why, always consider using a library
    Roberto Romello
    Business Head at Testree, Nous Infosystems

  4. #4
    Sencha User
    Join Date
    Apr 2017
    Posts
    3
    Vote Rating
    1
      0  

    Default

    Found the solution, just added a transform to decode the data after getting the data by using the Ext.JSON library.

    proxy: {
    type: 'ajax',
    url: '/Home',
    reader: {
    type: 'json',
    rootProperty: '/',
    transform: function (data) {
    var extdata = Ext.JSON.decode(data);
    return extdata;
    }
    }
    },

Similar Threads

  1. How to exchange data between two controllers
    By atul.sachan@capgemini.com in forum Ext: Q&A
    Replies: 1
    Last Post: 24 Sep 2012, 5:38 AM
  2. ASP.net JSON datetime exchange problem
    By bryanevil in forum Ext 3.x: Help & Discussion
    Replies: 9
    Last Post: 1 Jul 2010, 11:33 PM
  3. Ext.data.Record as data exchange object ?
    By Yuri in forum Community Discussion
    Replies: 0
    Last Post: 23 Oct 2008, 8:25 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •