【发布时间】:2012-04-20 10:16:58
【问题描述】:
我想在condition 上hide/show 和button,但不能在视图内进行。
@{
ViewBag.Title = "Mapping";
WebGrid grid = null;
if (ViewBag.Mappings != null)
{
grid = new WebGrid(source: ViewBag.Mappings,
defaultSort: "Id",
canPage: true,
canSort: true,
rowsPerPage: 10);
}
}
<h3>@ViewData["Message"]</h3>
@if (grid != null)
{
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("", header: null, format: @<text>@Html.ActionLink("Edit", "Index", new { uid = (Guid)item.id, userAction = "Edit" }, new { @class = "edit" })
@Html.ActionLink("Delete", "Index", new { uid = (Guid)item.id, userAction = "Delete" }, new { @class = "Delete" })</text>),
grid.Column("PricingSecurityID"),
grid.Column("CUSIP"),
grid.Column("Calculation")
)
)
}
if(@ViewBag.Mappings != null)
{
@Html.ActionLink("Update", "Index", new { userAction = "Update" }, new { @class = "Update" })
}
在上面的视图中,如果 ViewBag.Mappings != null 则我正在填充 webgrid。
如果填充了 webgrid,我需要在 webgrid 下显示一个Update 按钮,但是在条件下我哪里出错了?
【问题讨论】:
-
会发生什么?链接是否仍然生成?
-
你在控制器中设置 ViewBag.Mappings 吗?
标签: asp.net-mvc asp.net-mvc-3 model-view-controller