2011-07-06 2 views
1

나는이 클라이언트 측이 :문자열이 아닌 매개 변수가있는 jQuery로 WebMethod를 소비하는 방법은 무엇입니까?

$(document).ready(function() { 
    var $checkboxes = $('[type=checkbox]'); 
    $checkboxes.click(function() { 

     $checkbox = $(this); 

     $.ajax({ 
      type: "POST", 
      url: "Page.aspx/Method", 
      data: "{id:'" + $checkbox.attr("id") + "'}", 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function(msg) { 
       alert('success!'); 
      }, 
      error: function(xhr, status, error) { 
       var err = eval("(" + xhr.responseText + ")"); 
       alert('An error occurred that prevented your change being saved: ' + err.Message); 
      } 
     }); 
    }); 
}); 

을 그리고 난이 서버 측이 :

[WebMethod] 
public static void Method(String id) 
{ 
    Guid guidID = new Guid(classid)); 
    //........... 
} 

을하지만 강력하게 입력 한의 WebMethod 서명 할 원합니다 :

[WebMethod] 
public static void Method(Guid id) 
{ 
    //........... 
} 

이 작업을 수행하는 가장 좋은 방법은 무엇입니까?

답변

3

Guid를 메서드에 문자열로 전달하면 변환해야한다고 생각합니다. check this out

2

강력한 입력 매개 변수가있을 수 있습니다. 형식이 올바른 경우 메서드가 실행될 때 암시 적으로 올바른 유형으로 변환됩니다.

관련 문제