I'm start learning ASP.NET MVC 4 and stuck displaying Data From 2 model in 1 File Here's my Model
public class mst_item
{
[Key]
[DisplayName("Item Code")]
[Required]
public string item_code{get;set;}
[DisplayName("Item Name")]
[Required]
public string item_name{get;set;}
[DisplayName("Unit")]
[Required]
public mst_item_unit unit_id{ get; set; }
}
public class mst_item_unit
{
[Key]
public int unit_id { get; set; }
[DisplayName("Unit")]
public string unit_name { get; set; }
}
Then My Controller :
public ActionResult Item()
{
var list_item = db.mst_item.Include("mst_item_unit").ToList();
return View(list_item);
}
Then How to display the unit_name based on the mst_item.unit_id
in View using INNER JOIN
or Include
? something like :
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.item_name)
@Html.DisplayFor(modelItem => item.unit_name)
}
I get stuck here, But I success while displaying the mst_item
data without joining mst_item_unit
(just display the ID based on mst_item.unit_id
) before.