【发布时间】:2021-12-13 11:22:29
【问题描述】:
在我的应用程序中,在索引视图中,我想根据它们的值显示和隐藏一些按钮。需要大家帮忙做这个操作。
这是我的索引视图。
<div class="card-body p-0">
<table id="MyRequest" class="table table-striped">
<thead>
<tr>
<th style="width: 1%">
Request Number
</th>
<th>
Request Type
</th>
<th>
Created Date
</th>
<th>
Request Heading
</th>
<th>
Request Timeline
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.OrderByDescending(i => i.Id))
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReqestTypeDisplay)
</td>
<td>
@Html.DisplayFor(modelItem => item.Created_Date)
</td>
<td>
@Html.DisplayFor(modelItem => item.Req_Heading)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReqestApprovalStatus)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "btn btn-primary pull-right" })
@Html.ActionLink("Details", "Details", new { id = item.Id }, new { @class = "btn btn-warning pull-right" })
@Html.ActionLink("Approval", "Index", "ReportsViewModel", new { id = item.Id }, new { @class = "btn btn-success pull-right" })
@Html.ActionLink( "Delete", "Delete", new { id = item.Id },new { onclick = "return confirm('Are you sure you wish to delete this article?');", @class = "btn btn-danger pull-right" })
</td>
</tr>
}
</tbody>
</table>
</div>
RequestApprovalStatus 列中有值。我想启用编辑按钮,只有 Approval Status 值等于 At Department head 。否则,我想禁用编辑按钮,如果批准状态等于 Approved Only,则只能启用批准按钮。有人可以帮我解决这个问题。这可以使用 jQuery 完成吗?
【问题讨论】:
-
也许这样的事情会奏效。编辑“按钮”的类
new { @class = "btn btn-primary pull-right" + (item.ReqestApprovalStatus == "At Department head" ? "disabled":"") } -
@CarstenLøvboAndersen 谢谢。这种方法也行得通。并设置值“禁用”我替换了“btn-primary disabled”然后它起作用了。谢谢
标签: html jquery asp.net-mvc asp.net-mvc-4