I have an ASP.NET MVC 4 C# application and I want to display data from 3 different models in one view.
The schemas are related via foreign keys like this:
Model A | Model B | Model C
ID | ID | ID
A_ID | B_ID
In View for model A, I want to be able to to display data that is linked in B and C.
Right now, in the View for Model A (Details) I can do:
@model Application.Models.A
@foreach (var b Model.B)
{
@Html.DisplayFor(modelB => B.Title)
<br />
}
I want to be able to then do:
@foreach (var b Model.B)
{
@Html.DisplayFor(modelB => B.Title)
@foreach (var c Model.B.C)
{
@Html.DisplayFor(modelC => C.Title)
<br />
}
<br />
}
You can do this in ruby on rails, how can I do this in MVC 4?
I figured it out.
I had the models, controllers and relationships setup correctly. I just needed to modify my view to the following:
Thanks.