Required query string parameter in ASP.NET Core

前端 未结 5 1622
野性不改
野性不改 2020-12-18 22:11

Using ASP.NET Core 1.1 with VS2015 (sdk 1.0.0-preview2-003131), I have the following controller:

public class QueryParameters
{
    public int A { get; set;          


        
5条回答
  •  Happy的楠姐
    2020-12-18 23:06

    Use attribute routing and list each required parameter in the function's HttpGet attribute.

    [Route("api/[controller]")]
    public class ValuesController : Controller
    {
        [HttpGet("{A}")]
        public IEnumerable Get(int A, int B)
        {
           return new [] { A.ToString(), B.ToString() };
        }
    }
    

    This will require e.g /5 and allow /5?B=6 query url parameters.

提交回复
热议问题