在创建一个默认的Blazor应用程序(V0.5.1)之后,我们得到一个获取数据.cshtml从本地.json文件获取数据的页
@functions {
WeatherForecast[] forecasts;
protected override async Task OnInitAsync()
{
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}
class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF { get; set; }
public string Summary { get; set; }
}
}
这个很好用。但是,如果将此更改为从.net core rest web api获取相同的数据,则调用
Http.GetJsonAsync
挂起。没有错误,只是永远不会完成。
protected override async Task OnInitAsync()
{
forecasts = await Http.GetJsonAsync<WeatherForecast[]>(
"http://localhost:5000/api/weatherforecast/");
}
我错过了什么?