我在我的 ASP.net MVC 项目中创建了一个模型:
public class ProductListingModels:ItemEntityDataContext
{
public int ID { get; set; }
public string Name { get; set; }
public int DepartmentID { get; set; }
public int BrandID { get; set; }
}
我有一个控制器:
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
{
}
我想将我通过 linq (ien_item) 从数据库查询的每个数据添加到 ProductListingModel(prom object) 的对象中,然后将其作为 json 返回到我的视图中。
谁能给我一些想法。
非常感谢。