convert list to json

I'm  working on a C# 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  ( )

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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi maqskywalker;

This should do what you want.

// You will need to add System.Web.Extensions.dll 
// If not already added.
using System.Web.Script.Serialization;

// Create a serializer
private JavaScriptSerializer objJSSerializer = new JavaScriptSerializer();

// When you need to a Json you can do this with the instance on the
// object to be serialized as the parameter
string jsonStr = objJSSerializer.Serialize(the.Net.Instance.Object);

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.