I am working on a web application using ASP.NET MVC 4 and I want to fetch data from database using AngularJS.
My issue is that I have two tables (products, category) like below:
public partial class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string imgurl { get; set; }
public int CategoryId { get; set; }
public virtual Category Category { get; set; }
}
public partial class Category
{
public Category()
{
this.Products = new HashSet<Product>();
}
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
I want to iterate data using ng-repeat
from product table like this :
Name category
================
iphone - Mobiles
Only, I can retrieve data like :
Name category Id
================
iphone - 1
I can’t retrieve category name from category table. but I can retrieve categoryId.
Is there any way to get data from database in this format using ng-repeat
.
Name category
================
iphone - Mobiles
I want to get data from two tables already between them relationship .
Thanks in advance.
public JsonResult getAllProducts() { var products = db.Products.ToList(); return Json(products , JsonRequestBehavior.AllowGet); }