여기에 보이는 것처럼 Angular 2 프런트 엔드에서 값을 보냅니다.
censusManagementSearch(search: any): Observable<any> {
let headers = new Headers({ 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem('token') });
let options = new RequestOptions({ headers: headers });
let body = JSON.stringify({ practice: search.practice, location: search.location, name: search.name });
return this.http.post(this._api.apiUrl + 'censusmanagement', body, options)
.map((response: Response) => {
return response;
})
.catch((err: any) => {
return Observable.throw(err.json().error || 'Server error');
});
}
모든 것이 잘 작동합니다. 아래와 같이 C # 백엔드로 이동합니다. 중요한 경우 ASP.Net 핵심 웹 API
[HttpPost]
public IActionResult PostCensusManagement([FromBody] int practice, int location, string name)
여기에 중단 점을 놓았을 때 값은 정수의 경우 0이고 문자열의 경우 ""입니다. 나는 [FromBody]
그것을 꺼내고 다른 옵션으로 교체 하려고 시도 했습니다. 값이 비어있을 때마다.
답을 찾았습니다. 다른 사람이이 문제에 부딪 힐 경우를 대비하여 여기에 남겨 두겠습니다. 웹 API가 데이터를 보려면 클래스를 만들어야했습니다.
public class CensusSearch
{
public int location { get; set; }
public int practice { get; set; }
public string name { get; set; }
}
그리고 컨트롤러를 다음과 같이 변경했습니다.
[HttpPost]
public IActionResult PostCensusManagement([FromBody] CensusSearch search)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다