我想根据名为 status
的模型中的 bool 值显示接受、拒绝等引导徽章。这里的问题是我尝试使用 jquery 执行此操作,但它要么全部显示,要么全部隐藏。所以我猜它无法读取状态值。我打开开发者工具,没有报错。我需要指导。感谢您的帮助。
@for (int i = 0; i < Model._Requests.Count(); i++)
{
<tr>
<td>
@Html.DisplayFor(x => Model._Requests[i].Account_Name)
</td>
<td>
@Html.DisplayFor(x => Model._Requests[i].LOB)
</td>
<td>
@Html.DisplayFor(x => Model._Requests[i].Operation_Date)
</td>
<td>
@Html.DisplayFor(x => Model._Requests[i].Employee_no)
</td>
<td>
@Html.DisplayFor(x => Model._Requests[i].Fulfillment_Rate)
</td>
<td>
<span name="badge" class="badge badge-warning" id="pend">WTF</span>
</td>
<!--for the accept button-->
@using (Html.BeginForm("Add_Fulfillment_Accept", "TBL_Request", FormMethod.Post))
{
@Html.AntiForgeryToken()
<td>
<button id="btnAccept" class="btn btn-success" name="a_button" type="submit" value="true">Accept</button>
@Html.Hidden("Request_ID", Model._Requests[i].Request_ID)
@Html.Hidden("Status", Model._Requests[i].Status, new { id = "myEdit", value = "" })
</td>
}
<!--for the reject button-->
@using (Html.BeginForm("Add_Fulfillment_Reject", "TBL_Request", FormMethod.Post))
{
@Html.AntiForgeryToken()
<td>
<button id="btnReject" class="btn btn-danger" name="button" data-toggle="modal" data-target="#exampleModal" type="button" value="false">Reject</button>
@Html.Hidden("Request_ID", Model._Requests[i].Request_ID)
@Html.Hidden("Status", Model._Requests[i].Status, new { id = "myEdit", value = "" })
</td>
<!--this is the note modal of the reject button -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">New message</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
@Html.TextArea("Note", Model._Requests[i].Note, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<input type="submit" value="submit" class="btn btn-success" id="finalSave" />
</div>
</div>
</div>
</div>
}
</tr>
}
</tbody>
</table>
脚本
var flag = $('[name = "Status"]').val();
if (flag === false) {
$('#pend').show();
}
else {
$('#pend').hide();
}
我想要展示的徽章
<span name="badge" class="badge badge-warning" id="pend">WTF</span>
最佳答案
如果状态之后没有改变,只需在你的cshtml中动态地设置一些类给这个项目
<span name="badge" class="badge badge-warning @{Model.Status ? "visible" : "invisible"}" id="pend">WTF</span>
如果它确实发生变化,您必须触发该值变化的事件
关于javascript - 通过检查模型中的 bool 值来显示元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59718689/