你能告訴我什么是控制器方法 GetProfileById 的正確 url 與屬性 'id' 我嘗試了很多 url,如 ' http://localhost:5000/api/Profile/GetProfileById/1 '、' http://localhost:5000/ api/Profile/ProfileById/1 ',' http://localhost:5000/api/ProfileById/1 ' 但 Postman 顯示消息 'Cannot Get and my url'這是代碼:using System.Threading.Tasks;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;using SocialNetwork.Repositories;using SocialNetwork.Repositories.GenericRepository;namespace SocialNetwork.Controllers{ [Route("/api/[controller]")] public class ProfileController : Controller { private readonly ProfileRepository repository; public ProfileController(IProfileRepository repository) { this.repository = (ProfileRepository)repository; } [HttpGet("{id}")] [ProducesResponseType(200, Type = typeof(Profile))] [ProducesResponseType(404)] public async Task<ActionResult<Profile>> GetProfileById(int id) { var profile = await repository.GetById(id); if(profile != null) { return new OkObjectResult(Json(profile)); } return NotFound(); }}}
控制器的正確網(wǎng)址
慕田峪9158850
2021-11-21 18:02:35