1

如果记录字段“状态”已记录为已取消,我想禁用取消按钮。我已经知道如何禁用按钮,但问题是 jquery 如何知道记录字段“状态”已取消。这是代码

 @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>

任何帮助将不胜感激,谢谢:)

4

2 回答 2

1

If you know the status is cancelled you can disable it in the Razor itself.

    <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>

If you want to do it jquery way:-

$(function(){
$('.cancelSubmit').each(function(){
   if($(this).closest('tr').find('#Status_Name').text() === 'cancelled')
   {
       $(this).prop('disabled',true);
   }
  });
 });

or inside the function you could do :-

$(this).prop('disabled',
        $(this).closest('tr')
       .find('#Status_Name')
       .text() === 'cancelled');
于 2013-05-10T02:44:55.613 回答
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');
});
于 2013-05-10T02:45:22.507 回答