Link to home
Start Free TrialLog in
Avatar of maqskywalker
maqskywalker

asked on

convert list to json

I'm  working on a C# asp.net mvc 5 application and using Visual Studio 2013.
I'm using database first entity model and Entity Framework 6.

I'm using the Customers and Orders tables from the Northwind database.
My entity model is called northwindEF.edmx and contains a stored procedure called GetCustomerOrders.

Visual Studio  generated a function for my stored procedure called GetCustomerOrders_Result

So right now in my Models folder  of my application along with northwindEF.edmx  I also have a class called NorthwindModel.cs

The code for NorthwindModel.cs looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Objects;

namespace NorthwindSample.Models
{
    public class NorthwindModel
    {
        // an instance called customerordersdb of the NorthwindEntities
        NorthwindEntities customerordersdb = new NorthwindEntities();

        // a function called GetCustOrders that calls the GetCustomerOrders_Result collection and returns a list
        public List<GetCustomerOrders_Result> GetCustOrders()
        {
            return customerordersdb.GetCustomerOrders().ToList();
        }
        
    }
}

Open in new window


So I tried binding that function to a HTML Helper MVC Web Grid in my view and that function works fine.

No I'm trying to bind this function to a jquery Flexigrid  ( http://flexigrid.info )

In order to be able to bind it to flexigrid I have to convert  my list function shown above to a function that returns a json version of my list.   Because I have to feed flexigrid json type.

Anyone know the syntax for a json function that will convert my list function above to json data type?
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial