2010-04-09 3 views
12

클래스의 OnSuccess 함수에 매개 변수를 전달하는 방법은 무엇입니까?ASP.NET MVC에서 AjaxOptions 클래스의 OnSuccess 함수에 매개 변수를 전달하는 방법은 무엇입니까?

여기 내 코드입니다하지만 작동하지 않습니다 (function(){updateCount('parameter');})OnSuccess 속성을 설정

<%= Ajax.ActionLink("Delete", 
        "Delete", 
        "MyController", 
        New With {.id = record.ID}, 
        New AjaxOptions With 
        { 
         .Confirm = "Delete record?", 
         .HttpMethod = "Delete", 
         .OnSuccess = "updateCount('parameter')" 
        }) 
%> 

UPDATE

를 내 문제 해결 :

<%= Ajax.ActionLink("Delete", 
        "Delete", 
        "MyController", 
        New With {.id = record.ID}, 
        New AjaxOptions With 
        { 
         .Confirm = "Delete record?", 
         .HttpMethod = "Delete", 
         .OnSuccess = "(function(){updateCount('parameter');})" 
        }) 
%> 

답변

10

당신이해야을 사용할 수있다. JQuery와 선택기는 페이지의 필드에서 값을 채 웁니다 :

<%= Ajax.ActionLink("Delete", 
        "Delete", 
        "MyController", 
        New With {.id = record.ID}, 
        New AjaxOptions With 
        { 
         .Confirm = "Delete record?", 
         .HttpMethod = "Delete", 
         .OnSuccess = "updateCount($('#SomeField).val()))" 
        }) 
%> 

또한 여기 좀 봐 : Can I pass a parameter with the OnSuccess event in a Ajax.ActionLink 다음

+0

저를 링크 해 주셔서 감사합니다. 그 게시물을 보았지만 대답 중 하나를 간과했습니다. –

+0

@Dave, 생성 된 앵커를 성공 함수에 전달하는 방법은 무엇입니까? 나는 '이'를 시도했지만 효과가 없었다. – Shimmy

1

는 MVC4의 예이다. OnBegin, OnSuccess, OnComplete 및 OnFailure- 함수는 내 ajax 애니메이션을 활성화/비활성화하는 데 사용됩니다. 각 함수는 매개 변수로 항목 Id를 전달하여 모든 jax 함수에 대한 js 함수를 다시 사용할 수 있습니다. ajaxOnbegin()은 gif를 표시하고 ajaxOnsuccess가 다시 숨 깁니다.

<script> 
@*Ajax Animation*@ 
    $(document).ready(function() { 
     $("#ajaxLoadingGif").hide(); 
    }); 
    function ajaxOnbegin(id) { 
     //show animated gif 
     $(id).show(); 
    } 
    function ajaxOnsuccess(id) { 
     //disable animated gif 
     $(id).hide(); 
    } 
    function ajaxOnfailure(id) { 
     //disbale animated gif 
     $(id).hide(); 
    } 
    function ajaxOncomplete(id) { 
     //disable animated gif 
     $(id).hide(); 
    } 


    </script> 

@Ajax.ActionLink(linkText: " Hi", // <-- Text to display 
        actionName: "getJobCards", // <-- Action Method Name 
        routeValues: new { searchString = ViewBag.searchString}, 
        ajaxOptions: new AjaxOptions{ 
           "#itemId", // <-- DOM element ID to update 
           InsertionMode = InsertionMode.Replace, 
           HttpMethod = "GET", // <-- HTTP method 
           OnBegin = "ajaxOnbegin('#ajaxLoadingGif')", 
              //="ajaxOnbegin" without parameters 
           OnSuccess = "ajaxOnsuccess('#ajaxLoadingGif')", 
           OnComplete = "ajaxOncomplete('#ajaxLoadingGif')", 
           OnFailure = "ajaxOnfailure('#ajaxLoadingGif')" 
           }, 
           htmlAttributes: new { id = ViewBag.ajaxId } 

       ) 
관련 문제