【发布时间】:2011-05-07 23:33:14
【问题描述】:
我正在尝试从 System.Web.Helpers.WebGrid 中渲染 Partial
我的模型类如下所示:
class GameInfo
{
public List<AppUser> Team1 { get; set; }
public List<AppUser> Team2 { get; set; }
// and more properties
}
class AppUser
{
public string PictureUrl { get; set; }
public string ProfileUrl { get; set; }
public long GamesWon { get; set; }
public long GamesLost { get; set; }
public int Points { get; set; }
// and more properties
}
我希望我的 GridView 在我的网格视图中显示 GameInfo 的列表。 结果比预期更难的是渲染团队(列表)。 为了保持 DRY,我创建了一个局部视图来渲染团队 (_Team.cstml)。
这是我的剃须刀代码:
@if (Model != null)
{
var webgrid = new WebGrid(source: Model.Games,
rowsPerPage: 10);
<div id="grid">
@webgrid.GetHtml(
columns: webgrid.Columns(
webgrid.Column(header: "Score", format: @<text>@item.Score1/@item.Score1</text>),
webgrid.Column(header: "Team 1", format: (item) =>
{
return "hello sb"; // this line works!
//return Html.Partial("_Team", item.Team1); // this gives an error
})
)
)
</div>
}
知道如何让它工作吗?
谢谢!
【问题讨论】:
标签: asp.net-mvc-3