【发布时间】:2012-02-17 05:41:41
【问题描述】:
我目前正在掌握 ASP.Net MVC 3 和 Razor 模板引擎,但我遇到了一个我无法完全掌握的问题 - 所以请向 StackOverflow 社区寻求帮助!
假设我有一个看起来像这样的视图模型层次结构:
public class Foo {
public string FooTitle { get; set; }
[UIHint("BarList")]
public IList<Bar> BarList { get; set; }
}
public class Bar {
public string BarTitle { get; set; }
}
一切都相当简单,我相信你会同意的。要使用此视图模型,我有以下内容:
~/Views/Home/Index.cshtml
@model Foo
<h1>@Model.FooTitle</h1>
@Html.DisplayFor(m => m.BarList)
~/Views/Home/DisplayTemplates/BarList.cshtml
@model IEnumerable<Bar>
<div class="bar-list">
@Html.DisplayForModel()
</div>
~/Views/Home/DisplayTemplates/Bar.cshtml
@model Bar
<p>@Model.BarTitle</p>
我希望在执行 View 时找到要显示的 Bar.cshtml 的内容,但渲染似乎没有进一步嵌套 BarList.cshtml
我在这里做错了什么?
【问题讨论】:
标签: asp.net-mvc-3 razor