如果记录字段“状态”已被记录为已取消,我想禁用取消按钮。我已经知道如何禁用按钮,但问题是jquery如何知道记录字段“Status”是否已取消。 这是代码
@foreach (var rDetail in Model.Customers.ToList()) {
<tr>
<td>
@Html.DisplayFor(model => rDetail.DateEntry)
</td>
<td>
@Html.DisplayFor(model => rDetail.DateStart)
</td>
<td>
@Html.DisplayFor(model => rDetail.DateEnd)
</td>
<td>
@Html.DisplayFor(model => rDetail.Status.Name)
</td>
<td>
@Html.DisplayFor(model => rDetail.UserCode)
</td>
<td>
@Html.DisplayFor(model => rDetail.DateModified)
</td>
<td>
@Html.DisplayFor(model => rDetail.Remarks)
</td>
<td>
@Html.ActionLink("Details", "Details", "RoomReservation", new { id = rDetail.Id}, null) |
@using (Html.BeginForm("CancelReservation", "Rooms", new { roomId = Model.Id, reservationId = rDetail.Id, methodId = 0})) {
<input type="submit" value="Cancel" class ="cancelSubmit"/>
}
</td>
</tr>
感谢任何帮助,谢谢:)
答案 0 :(得分:1)
如果你知道状态被取消,你可以在Razor本身中禁用它。
<td>
@Html.ActionLink("Details", "Details", "RoomReservation", new { id = rDetail.Id}, null);
@if(rDetail.Status.Name.Equals("cancelled"))
{
<input type="submit" value="Cancel" class ="cancelSubmit" disabled/>
}
else
{
@using (Html.BeginForm("CancelReservation", "Rooms", new { roomId = Model.Id, reservationId = rDetail.Id, methodId = 0})) {
<input type="submit" value="Cancel" class ="cancelSubmit"/>
}
}
</td>
如果你想以jquery方式做到: -
$(function(){
$('.cancelSubmit').each(function(){
if($(this).closest('tr').find('#Status_Name').text() === 'cancelled')
{
$(this).prop('disabled',true);
}
});
});
或在你可以做的功能内: -
$(this).prop('disabled',
$(this).closest('tr')
.find('#Status_Name')
.text() === 'cancelled');
答案 1 :(得分:0)
如果我理解你,这样的事情应该有效:
$('#Status_Name').on('keypress', function(e) { //I think that's how the XFor handlers format ids
$('button_to_disable').prop('disabled', this.value === 'Cancelled');
});