我有一個角度表單,用戶輸入各種標準,然後我想傳遞給Web Api並在查詢運行後得到結果。我原本以爲這是一個「獲取」,但無法將複雜的對象傳遞給Web Api。有了一些建議之後,我使用了Post,並且能夠通過Web API中的條件運行查詢,但是我很難將結果返回到Angular。 Web Api方法運行並獲取結果。但我在數據服務中看不到結果。將Angularjs中的複雜對象傳遞到Web Api
查詢標準是多個字段而有些是列表的最佳方法是什麼?我一直沒有找到任何好的例子。
這裏是Web API方法:
[HttpPost] 公共IEnumerable的過帳([FromBody] FrequentPawnerReportCriteria條件) { 變種回購=新FrequentPawnerReport(); var result = repo.GetReport(criteria); 返回結果; }`
這裏是DataService在:
function getFrequentPawner(criteria) {
return $http.post("/api/FrequentPawner/Post", criteria)
.then (getFrequentPawnerComplete)
.catch(getFrequentPawnerFailed);
function getFrequentPawnerComplete(response) {
var x = response
return response.data.results;
}
function getFrequentPawnerFailed(error) {
alert("XHR failed for frequent pawner report: " + error.responseText);
}
}
這裏是控制器代碼:
function getTopPawnerResults(criteria) {
return DataContext.getFrequentPawner(criteria)
.then(
function (result) {
vm.frequentPawnerReport = result.data;
return vm.frequentPawnerReport;
});
}
請顯示代碼,列出迄今爲止您嘗試過的內容。如果您爲了清晰起見添加代碼,用戶將更有可能幫助您。 – buzzsaw
使用帖子或獲取不應該基於「我原本認爲這是一個」獲取「,但無法將複雜的對象傳遞到Web Api」 –
真的不清楚具體問題是什麼。來自服務器的響應不應該是獲得或發佈的問題 – charlietfl