在BlazorApp1创建Controllers文件夹,用来存放api文件,新建WeatherForecastController:
using Microsoft.AspNetCore.Mvc;
using SharedLibrary.Models;
namespace BlazorApp1.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class WeatherForecastController
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
[HttpGet("GetWeatherForecast")]
public IEnumerable<WeatherForecast> GetWeatherForecast()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.S