小编JPa*_*mar的帖子

无法从“System.Threading.Tasks.Task<string>”转换为“string”

我正在从 API 获取数据并尝试将其转换为反序列化形式。但出现这个错误。

public static async Task<List<Movie>> GetAllMovies(int pageNumber, int pageSize)
        {
            var httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));
            var response = httpClient.GetStringAsync(AppSettings.ApiUrl + String.Format("api/movies/AllMovies?sort=asc&pageNumber={0}&pageSize={1}",pageNumber,pageSize));
            return JsonConvert.DeserializeObject<List<Movie>>(response);

        }
Run Code Online (Sandbox Code Playgroud)

model-view-controller asp.net-mvc asp.net-mvc-viewmodel

1
推荐指数
1
解决办法
8172
查看次数

参数“res”隐式具有“any”类型

我正在尝试将 Angular HTML 页面数据发送到 MVC 核心。最后有兴趣得到回应。所以我使用 subscribe 方法,但它显示了这个错误 -

参数“res”隐式具有“any”类型。

这是我的代码

import { Component } from '@angular/core';
import { Patient } from './app.model';
import {HttpClient} from "@angular/common/http"
import { Observable, observable } from 'rxjs';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

    patientObj: Patient = new Patient();

    constructor(public httpClient:HttpClient){}

    Add() { 
        //https://localhost:44331/Patient/SubmitPatient ServerSide Page for display record
        alert(this.patientObj.id);
        var observable=this.httpClient.post("https://localhost:44331/Patient/SubmitPatient", this.patientObj);
    
        observable.subscribe(res=> this.Success(res), res=> this.Error(res));
    }
    
    Success(res) {
        alert(res);
    }
    
    Error(res) {
        alert(res);
    }
}


Run Code Online (Sandbox Code Playgroud)

编辑 …

angular

0
推荐指数
1
解决办法
2万
查看次数