2014-05-21 4 views
1

사전에서 JS를 MVC로 전달하려고 시도했습니다. 데이터 (mvc 컨트롤러의 reportIdAndStatus)는 null입니다.Java Script Angular 클라이언트에서 MVC3 서버로 사전을 전달하는 방법

저는 angular $ resource 및 MVC를 사용하고 있습니다. 3. 감사합니다.

각도 컨트롤러 :

var reportStatusdictionary = {}; 
//build a dictionary 
      for (var x = 0; x < reports.length; x++) { 
       reportStatusdictionary[reports[x].Id] = reports[x].StatusId 
      } 

reportsService.getReportStatusComment({ reportStatusdictionary: reportStatusdictionary } 

각도 자원 정의 :

getReportStatusComment: 
     { 
      method: 'GET', 
      params: { reportIdAndStatus: '@reportIdAndStatus', command: 'GetReportStatusComment' }, 
      isArray: false 
     } 

MCV 컨트롤러 : 브라우저에서

[HttpGet] 
    public string GetReportStatusComment(Dictionary<Guid, int> reportIdAndStatus) 

요청 :

enter image description here

+0

서버에서 클라이언트로 사전을 보내고 형식을 캡처하여 보내보십시오. – Chandermani

+0

POST metod를 사용하지 않는 이유는 무엇입니까? 내가 리소스를 변경하지 않기 때문에 – sylwester

+0

@ user3314659보다 쉬워야합니다. – MichaelLo

답변

0

사전 대신 디버그하기 쉽도록보기 모델을 만드는 것이 좋습니다. 당신은 다음과 같이 수행 할 수 있습니다

  1. 은 다음과 같은 뷰 모델을 만들기 :

    [HttpGet] 
    public string GetReportStatusComment(IEnumerable<ReportViewModel> reportViewModel) 
    
  2. 이 그런 다음 URL 가져 오기 될 것 같은
    public class ReportViewModel 
        { 
         public Guid Id{get;set;} 
         public int StatusId{get;set;} 
        } 
    
  3. 그런 다음 컨트롤러의 모양을

    http://localhost:53854/report/getreportstatuscomment?[0].id=guidValue1&[0].StatusId=1&[1].id=guidValue2&[1].StatusId=2

    JavaScript 코드에서 이와 같은 URL 구조를 쉽게 생성 할 수 있습니다. @Darin Dimitrov's answer, Phil Haack's blog postMSDN magazine article에서 모델 바인딩에 대해 자세히 읽을 수 있습니다. 해당 URL 구조를 구축하지 않으려면

업데이트

하는 당신은 서버에 JSON을 보낼 수 있습니다.

+0

개인적으로는 개인적으로 가능한 경우 프리미티브 \ 기본 제공 형식을 사용하는 경향이 있으므로보기 모델 옵션이 저에게 부담입니다. MSDN 기사에 관해서는 제시된 문제에 대한 오버 헤드 인 의상 값 공급자를 만드는 방법을 설명합니다. 나는 매우 간단한 조작을 시도하기 때문에 솔루션이 매우 간단하다고 예측합니다. – MichaelLo

관련 문제