Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6189445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:24:58+00:00 2026-05-24T02:24:58+00:00

I am using Entity Framework 4.1 code first and ASP.NET MVC 3. I have

  • 0

I am using Entity Framework 4.1 code first and ASP.NET MVC 3. I have a Yahoo User Interface (YUI) datatable on my view. I am getting the data (to populate the grid via JSON).

Flow of getting data:

Controller -> Service -> Repository

My context setup:

public DbSet<Category> Categories { get; set; }

Original Repositry:

public IEnumerable<Category> GetAll()
{
   return db.Categories.ToList();
}

Call to this repository method from my service layer:

public IEnumerable<Category> GetAll()
{
   return categoryRepository.GetAll();
}

My action method to retrieve the data and to pass it to the YUI datatable:

public ActionResult JsonCategoriesList()
{
   JsonEncapsulatorDto<Category> data = new JsonEncapsulatorDto<Category>
   {
      DataResultSet = categoryService.GetAll()
   };

   return Json(data, JsonRequestBehavior.AllowGet);
}

JsonEncapsulatorDto code:

public class JsonEncapsulatorDto<T>
{
   public IEnumerable<T> DataResultSet { get; set; }
}

When I use it this way then there is an error in the datatable. I don’t know how to view the error. Nothing is displayed. I debugged and I saw that there is a count of 7 in the DataResultSet. So what I did was to change the repository to use some test data and then it worked. What is the difference and how do I get it to display my results?

Repository with test data:

public IEnumerable<Category> GetAll()
{
   List<Category> list = new List<Category>();
   list.Add(new Category { Name = "Brendan" });
   list.Add(new Category { Name = "Charlene" });

   return list;
   //return db.Categories.ToList();
}

Not sure if you guys want to see my setup of the categories datatable:

<div id="dtCategories"></div>

<script type="text/javascript">

   YAHOO.util.Event.onDOMReady(function () {

      var yuiDataSource = YAHOO.util.DataSource;
      var yuiPaginator = YAHOO.widget.Paginator;
      var yuiDataTable = YAHOO.widget.DataTable;
      var dtCategoriesColumnDefs, dtCategoriesDataSource;
      var dtCategoriesConfigs, dtCategoriesDataTable;

      dtCategoriesColumnDefs = [
         { key: 'Name', label: 'Name' }
      ];

      dtCategoriesDataSource = new YAHOO.util.DataSource('@Url.RouteUrl      (Url.AdministrationCategoryJsonCategoriesList())');
      dtCategoriesDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
      dtCategoriesDataSource.responseSchema = {
         resultsList: 'DataResultSet',
         fields: [
            { key: 'Name' }
         ]
      };

      dtCategoriesDataTable = new YAHOO.widget.DataTable('dtCategories', dtCategoriesColumnDefs, dtCategoriesDataSource);

   });

</script>

UPDATE:

Category class:

public class Category
{
   public int Id { get; set; }
   public string Name { get; set; }
   public string Description { get; set; }
   public string MetaKeywords { get; set; }
   public string MetaDescription { get; set; }
   public bool IsActive { get; set; }
   public int? ParentCategoryId { get; set; }
   public virtual Category ParentCategory { get; set; }
   public virtual ICollection<Category> ChildCategories { get; set; }
}

Context class:

public class PbeContext : DbContext
{
   public DbSet<Category> Categories { get; set; }
   public DbSet<Tutorial> Tutorials { get; set; }

   protected override void OnModelCreating(DbModelBuilder dbModelBuilder)
   {
      dbModelBuilder.Entity<Category>()
         .HasOptional(c => c.ParentCategory)
         .WithMany(c => c.ChildCategories)
         .HasForeignKey(p => p.ParentCategoryId);
   }
}

UPDATE 2:

I have another view that that gets a list of Product objects (no circular references) and it populates fine. I debugged to see what the data looks like when it is returned. And this is how the objects looked like in the list:

Categories:

[0] [System.Data.Entity.DynamicProxies.Category_9E42BCEDDE8AA695F718BEBE2224E1D34291FCAF82F801F4995EEB8449479C93]
[1] [System.Data.Entity.DynamicProxies.Category_9E42BCEDDE8AA695F718BEBE2224E1D34291FCAF82F801F4995EEB8449479C93]
[2] [System.Data.Entity.DynamicProxies.Category_9E42BCEDDE8AA695F718BEBE2224E1D34291FCAF82F801F4995EEB8449479C93]

…and so on…

Products:

[0] = {MyProject.Core.DomainObjects.Product}
[1] = {MyProject.Core.DomainObjects.Product}
[2] = {MyProject.Core.DomainObjects.Product}

Can it maybe because of how the data is returned??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:24:59+00:00Added an answer on May 24, 2026 at 2:24 am

    No idea where your error is. Maybe a recursive Category model (usually that’s what happens when you don’t use view models and try to pass your EF domain models to the view)? In your example you only need to show a table containing one column which is the name of the category. Passing an entire domain IEnumerable<Category> is like a crime. Maybe missing scripts? Maybe this AdministrationCategoryJsonCategoriesList extension method?

    Here’s a full working example that I wrote for you and that might get you started:

    Model:

    public class Category
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public string MetaKeywords { get; set; }
        public string MetaDescription { get; set; }
        public bool IsActive { get; set; }
        public int? ParentCategoryId { get; set; }
        public virtual Category ParentCategory { get; set; }
        public virtual ICollection<Category> ChildCategories { get; set; }
    
        // Obviously this will be in your repository but for the purpose of
        // this demonstration let's hardcode some data
        public static IEnumerable<Category> GetAll()
        {
            List<Category> list = new List<Category>();
            list.Add(new Category { Name = "Brendan" });
            list.Add(new Category { Name = "Charlene" });
            return list;
        }
    }
    

    Controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    
        public ActionResult JsonCategoriesList()
        {
            var data = Category.GetAll().Select(x => new
            {
                // We select only what we need for our view => the name
                // if you need something else, well, select it here
                Name = x.Name
            }).ToList();
            return Json(new { DataResultSet = data }, JsonRequestBehavior.AllowGet);
        }
    }
    

    View:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>YUI Test</title>
        <link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/2.9.0/build/datatable/assets/skins/sam/datatable.css">
    </head>
    <body>
        <div id="dtCategories"></div>
    
        <script src="http://yui.yahooapis.com/2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
        <script src="http://yui.yahooapis.com/2.9.0/build/element/element-min.js"></script>
        <script src="http://yui.yahooapis.com/2.9.0/build/datasource/datasource-min.js"></script>
        <script src="http://yui.yahooapis.com/2.9.0/build/connection/connection-min.js"></script>
        <script src="http://yui.yahooapis.com/2.9.0/build/datatable/datatable-min.js"></script>
    
    
        <script type="text/javascript">
            YAHOO.util.Event.onDOMReady(function () {
                var yuiDataSource = YAHOO.util.DataSource;
                var yuiDataTable = YAHOO.widget.DataTable;
                var dtCategoriesColumnDefs, dtCategoriesDataSource;
                var dtCategoriesConfigs, dtCategoriesDataTable;
    
                dtCategoriesColumnDefs = [{ key: 'Name', label: 'Name'}];
    
                dtCategoriesDataSource = new YAHOO.util.DataSource('@Url.Action("JsonCategoriesList")');
                dtCategoriesDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
                dtCategoriesDataSource.responseSchema = {
                    resultsList: 'DataResultSet',
                    fields: [{ key: 'Name'}]
                };
    
                dtCategoriesDataTable = new YAHOO.widget.DataTable(
                    'dtCategories',
                    dtCategoriesColumnDefs,
                    dtCategoriesDataSource
                );
            });
        </script>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Entity Framework code first and ASP.NET MVC 3. I have the
I am currently using ASP.NET MVC and Entity Framework Code First using the repository
I am using Entity Framework 4.1 code first with ASP.NET MVC 3 and Razor
I'm using ASP.NET MVC 3 with the Entity Framework 4 code first approach and
I am using Entity Framework 4.1 code first and ASP.NET MVC 3 and I
I'm building an ASP.NET MVC 3 site using the code-first Entity Framework 4 approach.
I'm using ASP.NET MVC 3 and Entity Framework 4.1 Code First. Let's say I
I'm developing a web application using ASP.NET MVC 3 and Entity Framework Code First
I am using ASP.NET MVC 3 and Entity Framework 4.1 code first . I
First some brief background: I have an existing ASP.NET MVC 1 application using Entity

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.