这是我的索引视图,显示了一个表的结果。
我想屏蔽编辑链接或显示一些信息对话框("编辑锁定的选项。"):
@Html.ActionLink("Edit", "Edit", new { id = item.ID })
仅当此行的值:
@Html.DisplayFor(modelItem => item.IsActive)
等于1。
我怎样才能做到这一点?
索引视图:
@model ContosoUniversity.ViewModels.InstructorIndexData
@{
ViewBag.Title = "Instructors";
}
<h2>Instructors</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Is Active</th>
<th></th>
</tr>
@foreach (var item in Model.Instructors)
{
string selectedRow = "";
if (item.ID == ViewBag.InstructorID)
{
selectedRow = "success";
}
<tr class="@selectedRow">
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstMidName)
</td>
<td>
@Html.DisplayFor(modelItem => item.IsActive)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
}
</table>
请帮忙。
答案 0 :(得分:0)
如果要完全隐藏链接,请尝试以下操作:
@if (item.IsActive == 1)
{
@Html.ActionLink("Edit", "Edit", new { id = item.ID })
}
或者如果您想用文字替换它:
@if (item.IsActive == 1)
{
@Html.ActionLink("Edit", "Edit", new { id = item.ID })
}
else
{
<span>The option to edit locked.</span>
}