在我的應用程式中,在索引視圖中,我想根據它們的值顯示和隱藏一些按鈕。需要你們所有人的幫助來完成這項操作。
這是我的索引視圖。
<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>
HTML 視圖
RequestApprovalStatus列中有值。我只想啟用編輯按鈕,只有 Approval Status 值等于At Department head。否則我想禁用編輯按鈕,如果批準狀態等于僅批準,則只能啟用批準按鈕。有人可以幫助我了解如何做到這一點。這可以使用 jQuery 完成嗎?
uj5u.com熱心網友回復:
雖然可以使用客戶端 JS 執行您的要求,但如果您可以訪問服務器端的資料(如您的示例所示),那么到目前為止更好的方法是禁用服務器端的按鈕。
鑒于“按鈕”實際上是錨元素,禁用它們不像添加disabled屬性那么簡單。但是,從應用于元素的類的名稱來看,您似乎正在使用 Bootstrap。因此,您可以將disabled類添加到鏈接中,Bootstrap 庫將阻止您點擊鏈接。
話雖如此,試試這個:
@foreach (var item in Model.OrderByDescending(i => i.Id))
{
var editClass = item.RequestApprovalStatus == "At Department head" ? "" : "disabled";
<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 " editClass })
@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>
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/339752.html
標籤:html 查询 asp.net-mvc asp.net-mvc-4
