API를 처음 사용하기 때문에 ASP.NET MVC에서 상황이 발생합니다. 내 도메인 시스템에서ASP.NET MVC 프로젝트 : 복잡한 입력 매개 변수가있는 RESTful API 메서드
, 나는 그런 Invoice
서로 다른 개념을 가지고있다. 가 가능하다 어디하는 REST API를 만들려면 :
- 는
- 업데이트
- 삭제 선택 만들기 (다른 요소에 따라)
그러나, 예를 들어, 새 객체를 만들 때 많은 매개 변수 집합이 필요합니다 (아래 예제보기 모형 참조).
나는 이와 같은 경로를 예상하는 경우 :
POST - /api/invoice/create
어떻게 주위에 가서 양식 데이터를 받아 들일 것인가?
내 추측은 APIController을하고있는 유일한 매개 변수로 InvoiceViewModel
을 수용하는 것입니다. API 컨트롤러이므로 기본적으로 JSON을 허용한다고 가정합니다.
그런 다음 나는 다음과 같은 질문 (들)이 : jQuery를에
- , 나는에 JSON 객체를 구축 할 방법을이
InvoiceViewModel
"만족"을? - 더 복잡한 제품을 처리하는 가장 좋은 방법입니까?
InvoiceViewModel 다음 Asp.net-MVC 3 프레임 워크에 대한 기본 JsonValueProviderFactory가
public class InvoiceViewModel
{
public int Id { get; set; }
public string Comment { get; set; }
public InvoiceAddressViewModel CompanyInfo { get; set; }
public InvoiceAddressViewModel ReceiverInfo { get; set; }
public DateTime DateCreated { get; set; }
public List<InvoiceLineViewModel> Lines { get; set; }
public decimal Total { get; set; }
public decimal VatTotal { get; set; }
public decimal VatPercentage { get; set; }
public decimal TotalExVat { get; set; }
public InvoiceViewModel()
{
this.Lines = new List<InvoiceLineViewModel>();
}
}
public class InvoiceAddressViewModel
{
public string Name { get; set; }
public string Address { get; set; }
public string Company { get; set; }
public string VatNumber { get; set; }
public string Country { get; set; }
public string ZipCode { get; set; }
public string City { get; set; }
}
public class InvoiceLineViewModel
{
public string Title { get; set; }
public int Quantity { get; set; }
public decimal Price { get; set; }
}
위와 같이 추가하면 Ajax를 사용할 수도 있습니다.BeginForm을 호출하고 AjaxOptions의 Url 매개 변수에서 웹 API URL을 지정하십시오. 이 stackoverflow에 대한 답변을보십시오 제 답변 http://stackoverflow.com/questions/16510873/html-beginform-routing-to-web-api – Amila