2012-11-28 3 views
0

완벽하게 작동하는 토글 버튼이 있습니다. 자바 스크립트와보기는 다음과 같습니다 :컨트롤러에 아약스 게시하기 전에 jquery 대화 confimation + asp .net mvc3 + C#

jQuery를 :

$('.list-delist-link').delegate("a", "click", function (e) { 
    var obj = $(this); 
    if ($(this).hasClass('delist-property')) { 
     // Post to controller 
     e.preventDefault(); 
    } else { 
     // Post to controller 
     e.preventDefault(); 
    } 
}); 

보기 :

<div class="list-delist-link"> 
    @if(item.IsPropertyDisabled) { 
     @Html.ActionLink("List", "Enable", "Property", new { id = item.PropertyId }, new { @class="list-property other-button" }) 
    } else { 
     @Html.ActionLink("Delist", "Disable", "Property", new { id = item.PropertyId }, new { @class="delist-property other-button" }) 
    } 
</div> 

그러나, 지금은 아약스 작업을하기 전에 확인 대화 상자를 추가하고 싶습니다. 그러나, 그 일을하려고 할 때 모든 것이 깨집니다 ... 나는 왜 확신하지 못합니다. 나는 레이아웃 페이지에 jQuery를 및 CSS 파일이 내가 만든

의 변경 사항은 다음과 같습니다 :

변경 JQuery와에 :

var obj; 
$('.list-delist-link').delegate("a", "click", function (e) { 
    obj = $(this); 
    $("#dialog-confirm").dialog(open): 
    e.preventDefault(); 
}); 

추가 jQuery를 모달 확인 :

$(function() {   
    $("#dialog-confirm").dialog({    
     resizable: false, height:140, modal: true, 
     buttons: { 
      "Delete all items": function() { 
       if (obj.hasClass('delist-property')) { 
        // Post to controller 
       } else { 
        // Post to controller 
       } 
       $(this).dialog("close");     
      }, 
      Cancel: function() { 
       $(this).dialog("close"); 
      }    
     } 
    });  
}); 

보기의 추가 div :

<div id="dialog-confirm" title="Are you sure?"> 
     <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p> 
</div> 

무엇이 잘못되었는지 말씀해 주시겠습니까?

답변

0

이이

$("#dialog-confirm").dialog({ 
     autoOpen : false, 
     resizable: false, height:140, modal: true, 
     buttons: {...... 
+0

나는 그것을 시도 할 것이다 보면, autoOpen: false를 추가해야하지만 링크도 jQuery를 이동하지 않기 때문에이 문제라고 생각 해달라고 ... 그리고 직접적 페이지로 이동 및 도착 POST 작업을 통해서만 액세스 할 수 있으므로 404 오류가 발생합니다. 나는 심지어 위임 클릭에 경고를 두려고했지만 클릭은 jQuery에 들어 가지 않는다 ... 어떤 생각? – Tripping

+0

'$ ("# 대화 상자 확인") 대화 상자 (열기)'대화 상자 열기()' –

+0

을 사용하고'@ Html.ActionLink' 대신'@Ajax.ActionLink'를 사용하십시오. –