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 7806933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:41:29+00:00 2026-06-02T02:41:29+00:00

I created one model in my ASP.net MVC Project : public class ProductListingModels:ItemEntityDataContext {

  • 0

I created one model in my ASP.net MVC Project :

public class ProductListingModels:ItemEntityDataContext
{
  public int ID { get; set; }
  public string Name { get; set; }
  public int DepartmentID { get; set; }
  public int BrandID { get; set; }
 }

And I have one controller :

public class ProductListingController : Controller
{
   // GET: /ProductListing/
   public JsonResult Index(string depID)
   {
   Context DataContext = new Context();
   JsonResult jr = new JsonResult();
   int dep = Convert.ToInt32(depID);
   var ien_item =   from i in DataContext.DataContext.Items
        join c in DataContext.DataContext.Categories on i.CategoryID equals c.ID
        join d in DataContext.DataContext.Departments on i.DepartmentID equals d.ID
        join brand in DataContext.DataContext.Brands on i.BrandID equals brand.ID
        orderby i.LastUpdated descending
        where i.DepartmentID == dep && i.Active > 0 && i.WebsiteShow > 0 && c.Active > 0 

                    select i;

     List<ProductListingModels> prom = new List<ProductListingModels>();
     //
     //Adding ien_item to the prom
     //
     jr.Data = prom;
         jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
         return jr;
   }
}
public class Context : ICEWeb.Models.ItemEntityDataContext
{

}

I want to add each data that I have query from database by linq (ien_item) to the object of ProductListingModel(prom object),
and then return it as the json to my view.

Could anyone give me some ideas please.

Thanks so much.

  • 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-06-02T02:41:32+00:00Added an answer on June 2, 2026 at 2:41 am

    First, your model shouldn’t be inheriting from the data context. Passing your entire context to the view seriously violates the separation of concerns that is fundamental to MVC. Second, you should simply select into elements of the view type, then call ToList() on the result.

    var model = (from i in DataContext.DataContext.Items
                 join c in DataContext.DataContext.Categories on i.CategoryID equals c.ID
                 join d in DataContext.DataContext.Departments on i.DepartmentID equals d.ID
                 join brand in DataContext.DataContext.Brands on i.BrandID equals brand.ID
                 orderby i.LastUpdated descending
                 where i.DepartmentID == dep && i.Active > 0 && i.WebsiteShow > 0 && c.Active > 0 
                 select new ProductListingModels
                 {
                     ID = i.ID,
                     Name = i.Name,
                     ...
                 }).ToList();
    

    Then simply return the data using the Json() convenience method rather than constructing your own response.

     return Json( model, JsonRequestBehavior.AllowGet );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following models in my ASP.NET MVC 3 project: public class Task
I'm working in an ASP.NET MVC project where I have created a two LinqToSQL
I'm building an ASP.Net MVC website. Rather than have everything in one project, I've
I'm currently working on an Intranet application project, using ASP.NET MVC 3. One of
I have created a paginatedList and pager for that for my ASP.NET MVC project.
I'm pretty new to ASP.Net MVC. I've created a model that fills a List<>
I am working on asp.net MVC 3 application and I have created a model.
I'm in the process of developing an ASP.NET MVC project, and after several weeks
I have an ASP.NET MVC 4 project with a lot of models to be
My ASP.NET MVC 2 application uses Entity Framework 4.0 for the data model. Following

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.