2017-05-02 7 views
0

MVC 5アプリで作業しています。それは次のようにレンダリングされます確認後にURLに移動

@Html.ActionLink("Delete Chart " + Model[0].CurrentChartNumber,            
      "DeleteChartData", 
      new { eventId = Model[0].EventId, 
       chartNumber = Model[0].CurrentChartNumber }, 
      new { @class = "btn btn-danger btnDelete" }) 

私のように定義されたボタンを持つ

.... ...

<a class="btn btn-danger btnDelete" 
    href="/AuditResults/DeleteChartData?eventId=50&amp;chartNumber=1"> 
    Delete Chart 1 
</a> 

私は削除の確認のためsweetAlertを使用しています。すべてうまく動作しますが、ユーザーが「はい」をクリックすると定義済みのhrefに移動することはできません。ここでは、ユーザーがはいをクリックした場合

<script> 
$(function() { 
    $(".btnDelete").click(function(e) { 
     e.preventDefault(); 
     swal({ 
      title: 'Are you sure you want to DELETE this chart?', 
      text: "You won't be able to undo this!", 
      type: 'warning', 
      showCancelButton: true, 
      confirmButtonColor: '#3085d6', 
      cancelButtonColor: '#d33', 
      confirmButtonText: 'Yes!' 
     }).then(function() { 
      //user selected "Yes" 
      return true; 
     }); 

    }); 

}) 
</script> 

だから、それはへ....

/AuditResults/DeleteChartData?eventId=50&amp;chartNumber=1  

ナビゲートする必要があります...しかし、それはどこにも移動しません... javascriptのコードです。 (私はe.preventDefault()を削除して試してみました。)何が間違っているの?ありがとう!

+0

標準の 'confirm()'で動作しますか? – Crowcoder

+1

削除アクションはデータを変更しています。それはGETではなくPOSTでなければなりません。 –

答えて

2

ユーザーが「はい」を選択すると、約束から真実を返すだけで何もしていません。コードブロック内のページにリダイレクトを追加してみてください。

<script> 
$(function() { 
    $(".btnDelete").click(function(e) { 
     e.preventDefault(); 
     swal({ 
      title: 'Are you sure you want to DELETE this chart?', 
      text: "You won't be able to undo this!", 
      type: 'warning', 
      showCancelButton: true, 
      confirmButtonColor: '#3085d6', 
      cancelButtonColor: '#d33', 
      confirmButtonText: 'Yes!' 
     }).then(function() { 
      //user selected "Yes" 
      window.location.replace("AuditResults/DeleteChartData?eventId=50&amp;chartNumber=1"); 
      return true; 
     }); 

    }); 

}) 
</script> 
関連する問題