您有包含照片查看模型列表的页面的查看模型。此页面视图模型包含照片的视图模型列表。 在查看主网页呼叫:
@Html.DisplayFor(m => m.PhotosView)
这将使用您定义的默认视图渲染每个视图模型。
编辑
class MainPageController
{
ActionResult Index()
{
var model = new MainPageViewModel
{
Photos = GetListOfPhotoViewModelsOrderedByAge(SomeDataSource),
}
return View(model)
}
class MainPageViewModel
{
// various other properties
IList<PhotoViewModels> Photos {get; set;}
}
class PhotoViewModel
{
// properties to display about the photo (including hte path to the actual image)
}
剃刀次(炫魅)
@model MainPageViewModel
@Html.DisplayFor(m =>m.Photos)
@* other things on the page *@
图片视图(在共享/显示目录)
@model PhotoViewModel
<img url="@Model.PathToImage" />
我还没有试过这并且它主要来自我的头顶,可能是轻微的语法错误。
这需要我的主页使用照片模型,虽然,对吧? – 2015-02-12 02:12:06
@JohnShedletsky是的主页面会有一个照片视图模型列表。我会用更好的解释示例更新我的答案。 – THBBFT 2015-02-12 02:19:26