2014-01-20 5 views
3

웹 API 메서드를 호출하고 있습니다.자바 스크립트의 전통적인 쿼리 문자열 매개 변수 #

API 방법 :

사실
//get 
public bool GetShoppingElementDetails(ElementSearchParameter elementSearchParameter) 
{ 

} 

class ElementSearchParameter{ 
    public string name; 
    public list<int> ids; 
} 

그 방법은 get 메소드입니다, 그래서 내가 어떻게 그 기능에 multidimention 배열 매개 변수를 전달할 수 있습니다, 내가 같은 생각

, JQuery와 프레임 워크는 전체 개체를 변환한다 "traditional = true"를 사용하여 올바른 쿼리 문자열로 변환하므로 mvc 컨트롤러가 완벽하게 구문 분석합니다.

C와 동일한 방식으로하고 싶습니다. 다음과 같은 뭔가,

ElementSearchParameter toSearch = new ElementSearchParameter{}; 

//convert the tosearch object into string object (parsing like jquery) 
string toSearchString = ... 

    HttpResponseMessage response = httpManager.Client.GetAsync(string.Format(_routePrefixMeta + "/OrderOffering/Elements/search/{1}", programID, toSearchString)).Result; 
      return httpManager.ConstructData<List<OfferElementType>>(response); 
+0

저는 C#에서 호출하는 javascript에서 컨트롤러 메서드를 호출하지 않습니다. (WEB-API) – sathishkumar

답변

0

난 당신이 쿼리 문자열에 여러 개의 ID를 전달하고이를 IEnumerable로 해결 한 방법을 알고 싶은 생각?

이 작업을 수행하는 유일한 방법은 사용자 지정 ModelBinder를 사용하는 것입니다. 비슷한 내용의 예제를 찾을 수 있습니다. How to pass an array of integers to ASP.NET Web API?

위의 링크에서 설명한대로 :/Categories? categoryids = 1,2,3,4 및 ASP.NET 웹 API는 categoryIds 배열을 올바르게 바인딩합니다. .

+0

감사합니다. 복잡한 객체 컬렉션을 전달하려고합니다. int, string 등의 컬렉션이 아닙니다. – sathishkumar

+0

안녕하세요, 같은 것을 제외하고 문자열 형식으로 직렬화하는 방법이 필요합니다. 개체 바인드를위한 모델 바인더 –