返回的查詢的結果,這是我在得到的產品ID,並使用JSON返回supllier控制器方法:不能查看我使用JSON
public ActionResult GetProductData(int ProductId)
{
var data = from m in db.Products
join sa in db.SupPro on m.ProductID equals sa.ProductID
join f in db.Supplier on sa.CompanyID equals f.CompanyID
where m.ProductID == ProductId
select new { CompanyName = f.NameS, AdressCompany = f.Address, PhoneCompany = f.Phone };
return Json(new { foo = data.ToList(), ball = "dragon", elementId = ProductId }, JsonRequestBehavior.AllowGet);
}
在屏幕上的輸出是:數據水庫:[對象的對象]龍4
這些都是我的模型類:
客戶模式:
public class Customer
{
[Key]
public int CustomerID { get; set; }
public String NameS { get; set; }
public String NameP { get; set; }
public String Name { get; set; }
public String Phone { get; set; }
public String Address { get; set; }
public String Email { get; set; }
public virtual ICollection<SupPro> SupPro { get; set; }
}
的供應者類:
public class Supplier
{
[Key]
public int CompanyID { get; set; }
public String NameS { get; set; }
public String Address { get; set; }
public String Phone { get; set; }
public virtual ICollection<SupPro> SupPro { get; set; }
}
產品類:
public class Products
{
[Key]
public int ProductID { get; set; }
public String NameP { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }
public virtual ICollection<SupPro> SupPro { get; set; }
}
和supPro類:
public class SupPro
{
[Key]
public int SupProID { get; set; }
public int CustomerID { get; set; }
public int ProductID { get; set; }
public int CompanyID { get; set; }
public DateTime SupplyDate { get; set; }
public virtual Products Product { get; set; }
public virtual Supplier Supplier { get; set; }
public virtual Customer Customer { get; set; }
}
有人可以告訴我什麼是我的問題,所以我將能夠根據需要查看查詢結果。
謝謝。
這可以幫助你的http:// www.mkyong。com/javascript/how-to-access-json-object-in-javascript/ –
向你展示客戶端代碼! –
您無法直接將json數據「打印」到瀏覽器。你需要迭代json對象並使用單獨的屬性。否則,您需要使用某種綁定庫,如'knockout.js'來處理客戶端與您的html的json綁定。 – ramiramilu