2013-09-30 42 views
0

您好我是MVC和jQuery的新手。 任何人都可以请引导我下面请。 当我点击删除链接时,删除操作从未命中。JQuery确认没有命中控制器中的操作方法

笔者认为:

<table id="lookupValuesDetailsTable" class="table table-bordered table-striped table-hover"> 
     <thead> 
      <tr> 
       <th>Value</th> 
       <th>Message</th> 
       <th>EffectiveDate</th> 
      </tr> 
     </thead> 
     <tbody> 
      @foreach (var item in Model.LookupValues) 
      {    
       <tr> 

        <td>@Html.DisplayFor(m => item.Value)</td> 
        <td>@Html.DisplayFor(m => item.Message)</td> 
        <td>@Html.DisplayFor(m => item.EffectiveDate)</td> 
        @* <td>@Html.DisplayFor(m => item.EffectiveDateDateForSorting)</td>*@ 
        <td> 
         @Html.ActionLink("Delete", "Delete", "LookupValues", new { area = "Admin", id = item.LookupValueKey }, new { @class = "deleteLink" }) 

        </td> 
       </tr> 
      } 

     </tbody> 
    </table> 

<div id="dialog-confirm" title="CONFIRMATION" class="modal-header"> 
    <div class="modal-body"> 
     <p>This item will be deleted. Are you sure?</p> 
    </div> 
</div> 


@section Scripts { 
<script type="text/javascript"> 
    $("#dialog-confirm").dialog({ 
     autoOpen: false, 
     modal: true, 
     resizable: false, 
     height: 180, 
    }); 

    $(".deleteLink").click(function (e) { 
     e.preventDefault(); 
     var targetUrl = $(this).attr("href"); 

     $("#dialog-confirm").dialog({ 
      buttons: { 
       "Confirm": function() { 
        window.location.href = targetUrl; 
       }, 
       "Cancel": function() { 
        $(this).dialog("close"); 
       } 
      } 
     }); 

     $("#dialog-confirm").dialog("open"); 
    }); 

</script> 

我控制器(LookupValuesController):

[HttpPost] 
    public ActionResult Delete(Guid id) 
    { 
     var lookupValueDetails = adminService.GetLookupValues(id); 
     var model = AddLookupValueMappings.ToModel(id, lookupValueDetails); 
     return View(); 
    } 

谁能告诉我,我在做什么错。

+0

您好,我试图删除的是,现在我连能看到模式弹出。尽管没有达到行动方法。 –

+0

为什么你为同一个id写了2次对话函数?删除第一个,并检查它 –

回答

0

先删除e.Prevntdefault();然后尝试below..i还没有检查它虽然...

$('.delete').click(function() { 
      var answer = confirm('Do you want to delete this record?'); 
      if (answer) { 
       $.post(this.href, function() { 
        window.location.reload(); //Callback 
       }); 
       return false; 
      } 
      return false; 
     }); 

和控制器如下: -

@Html.ActionLink("Delete", "Delete", new { area = "Admin", id = item.LookupValueKey }, new { @class = "delete" }) 
+0

对话框您的第二次尝试就够了我的意思是把这个代码放在$(“#dialog-confirm”)。dialog({})并在结束时打开对话框...下面的代码我用简单的确认框代替了对话框 – Neel

相关问题