.net 코어 앱에서 Wirking 및 시작 설정은 다음과 같습니다.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
커스텀 컨트롤러가 있으며 컨트롤러의 정의는 다음과 같습니다.
[Route("Purchase")]
public class InvoiceController : Controller
{
[HttpGet("{identifier}/{itemsCount}/overview")]
public async Task<IActionResult> GetInvoiceOverview(string identifier,int itemsCount)
{
A call to url like this //https://localhost:44320/invoice/20210209-0035/20/overview/
is working correctly and getting param values as
identifier=20210209-0035
itemsCount=20
}
}
이 목록에 하나 이상의 선택적 매개 변수를 추가하려고하는데 새 작업 정의는 다음과 같습니다.
[HttpGet("{identifier}/{itemsCount}/{pagesize?}/overview")]
public async Task<IActionResult> GetInvoiceOverview(string identifier,int itemsCount,string pagesize=null)
{
}
이 ruting 규칙은 아래 https : // localhost : 44320 / invoice / 20210209-0035 / 20 / 11 / overview /와 같이 pagesize의 모든 null이 아닌 값에 대해 작동하는 것 같습니다.
identifier=20210209-0035
itemsCount=20
pagesize=11
그러나 pagesize의 null 값으로 호출을 시도하면 응용 프로그램이 404 페이지를 찾을 수 없음
이 URL을 반환합니다 . https : // localhost : 44320 / invoice / 20210209-0035 / 20 / overview / => 404
그 이유는 무엇일까요?
2 개의 속성 경로를 사용해 볼 수 있습니다.
[HttpGet("~/invoice/{identifier}/{itemsCount}/overview")]
[HttpGet("~/invoice/{identifier}/{itemsCount}/{pagesize:int}/overview")] //:int is optional
public async Task<IActionResult> GetInvoiceOverview(string identifier, int itemsCount, int? pagesize)
{
....
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다