2011-02-02 7 views
8

:의 아웃 오류가 발생한MVC3 Ajax.ActionLink

@Ajax.ActionLink("Delete", "Delete", "AdminGroup", new { id = item.AdminGroupId }, new AjaxOptions { Confirm = "Delete?", HttpMethod = "Delete", OnSuccess = "function() { $(this).parent().parent().remove() }" }) 

onsuccess는 GET. 도와주세요. 감사

답변

23

그것은 다음과 같이해야한다 : 당신이

@Ajax.ActionLink(
    "Delete", 
    "Delete", 
    "AdminGroup", 
    new { id = item.AdminGroupId }, 
    new AjaxOptions { 
     Confirm = "Delete?", 
     HttpMethod = "Delete", 
     OnSuccess = "handleSuccess" 
    } 
) 

: 여기


<script type="text/javascript"> 
function handleSuccess() { 
    // TODO: handle the success 
    // be careful because $(this) won't be 
    // what you think it is in this callback. 
} 
</script> 
대안 솔루션입니다 내가 당신을 추천 할 것입니다 :

@Html.ActionLink(
    "Delete", 
    "Delete", 
    "AdminGroup", 
    new { id = item.AdminGroupId }, 
    new { id = "delete" } 
) 

과 그 다음에 .. parate 자바 스크립트 파일 링크 AJAXify :

$(function() { 
    $('#delete').click(function() { 
     if (confirm('Delete?')) { 
      var $link = $(this); 
      $.ajax({ 
       url: this.href, 
       type: 'DELETE', 
       success: function(result) { 
        $link.parent().parent().remove(); 
       } 
      }); 
     } 
     return false; 
    }); 
}); 
+0

이 "$ (이) .parent을 반환 어쨌든이을() 부모()를 제거(); : 컨트롤러에서 실행하고 실행 하시겠습니까? – ShaneKm

+0

@Shane, 컨트롤러에서 당신은'$ (this)) .parent(). parent(). remove(); ");를 호출 할 수 있지만'$ (this) 당신은 기대할 수 있습니다. 개인적으로 나는 컨트롤러가 자바 스크립트를 반환하지 않았을 것이다. 나는 성공 콜백에서 그것을 처리 할 것이다. –

+0

@Darin, Darin이 Ajax를 추천하지 않는다고 생각해야합니까? ActionLink? 감사합니다 –

관련 문제