2
모델 컬렉션 (/api/models
)에 여전히 모호하지 않은 액세스를 허용하면서 쿼리 매개 변수 기반 경로 (/api/models?id=1
)와 경로 기반의 하나 (/api/models/1
)를 동시에 지원해야합니다.FromQuery와 FromRoute 매개 변수를 동시에 바인딩하는 방법은 무엇입니까?
내 컨트롤러 보이는이 같은 (뭔가) :
[Route("/api/{controller}")]
public class ModelsController : Controller
{
[HttpGet]
public Models[] GetModels([FromQuery]QueryOptions queryOptions)
{
//...
}
[HttpGet("{id:int}")]
public Model Get([FromRoute] int id)
{
//...
}
[HttpGet("?{id:int}")]
public Model Get2Try1([FromQuery] int id)
{
//Fails with ": The literal section '?' is invalid.
//Literal sections cannot contain the '?' character."
//Which makes sense after some reading...
}
[HttpGet]
public Model Get2Try2([FromQuery] int id)
{
//Fails with "AmbiguousActionException: Multiple actions matched.
//The following actions matched route data and had all constraints satisfied:
//GetModels and Get2Try2"
//Which I think I understand as well...the absence of optional params
//means ambiguous routing...
}
[HttpGet] //What here?
public Model Get2Try3([FromQuery] int id) //and/or here?
{
}
}
몇 가지 방법이 있어야한다처럼 내가 (선언적 라우팅) 느낌이 작업을 수행. 이 라인을 따라 아무 일도하지 않았습니까?
또한 현재 코드베이스는 RTM/1.0으로 곧 업그레이드 될 ASP.NET 코어 (RC1)입니다. 양 측면에 대한 세부 사항은 유사 할 수도 있지만 양쪽 모두에 관심이 있습니다.
이 나를 위해 작동하지 않습니다입니다하지 않습니다. [FromRoute]로 작동하며 [FromQuery]로 작동하지 않습니다. – neeohw