I have a view with strongly typed model view and i need to pass this data to a partial view, in loop. (the partial view is sorta playing role of template for data)
Model:
public class Foo {
public int Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
}
Controller:
public ActionResult Index()
{
var foo = new List<Foo>();
for (var i = 1; i < 3; i++)
{
foo.Add(new Foo{Content = "test content " + i, Title = "test title " + i, Id = i});
}
return View(foo);
}
View (Index):
@model List<Project.Models.Foo>
@foreach (var foo in Model)
{
Html.RenderPartial("OneFoo", foo);
}
View (OneFoo):
@using Project.Models
<div>
Title:
@Html.LabelFor(f => f.Title)
Content:
@Html.LabelFor(f => f.Content)
}
</div>
The output I'm getting is: Title: Title, Content: Content - it's not getting the actual values.