2016-11-03 2 views
0

나는이 자바 스크립트 코드 조각이 : 나는 전화를 걸 때HTTP POST를 방법 HTTP GET 방법

[HttpPost] 
public List<ItemStatistiquesPointageMonth> GetPointages(Nullable<System.DateTime> laDate = null, List<Collaborateur> lstcols =null, Nullable<int> lEquipe = null, int Type = -1) 

가의 경호 국은 다음과 같습니다

$.ajax({ 
       type: "Post", 
       contentType: 'application/json', 
       url: "../api/Pointage/GetPointages", 
       data: JSON.stringify({ 
        laDate: DateConsultation, 
        lstcols: Collaborators, 
        lEquipe: equipe, 
        Type: 3, 
       }), 
       success: function (data) { 
        console.log(data); 
        call3(data); 
       } 
      }); 

서비스 메소드의 서명이 다음입니다 도달 할 수 없다 !!

그래서이 문제의 이유는 무엇입니까? 어떻게 해결할 수 있습니까?

+1

시도가'대신 type''의 method' - 우리가 아약스 호출에서 볼 수 있듯이 내가 jQuery를 모두 지원합니다 생각하지만, 여기에 –

+1

(아마도 JQuery와 버전에 따라 다름), 당신은 데이터 트로프 몸,하지만 방법에 전달하는에이 '[FromBody]'를 선언하지 말고, 어떻게 여러 개의 매개 변수를 이런 식으로 전달할 수 있습니까? –

+0

@Div가 지적했듯이, 그 속성을 가진 모델을 생성 해보고 대신 액션 인수로 사용 해보십시오. –

답변

1

은 클라이언트에서 만든 객체를 반영하는 모델 클래스를 만들고 사용하여 PARAMATERS와 모델을 만들고 게시 방법에 전달

public class dataModel 
{ 
    public Nullable<System.DateTime> laDate { get; set; } 
    public List<Collaborateur> lstcols { get; set; } 
    public Nullable<int> lEquipe { get; set; } 
    public int Type { get; set; } 
} 

그런 다음 FromBody 특성을 사용하여 메서드에 추가하십시오.

[HttpPost] 
public List<ItemStatistiquesPointageMonth> GetPointages([FromBody] dataModel data){} 
1

[HttpPost] 
public List<ItemStatistiquesPointageMonth> GetPointages([FromBody] MyModel model) 

dataType: "json"

관련 문제