Pass multiple parameters in a POST API without using a DTO class in .Net Core MVC

后端 未结 5 1193
旧巷少年郎
旧巷少年郎 2021-02-15 16:53

I have an action on my web project which calls to an API

    [HttpPost]
    public async Task ExpireSurvey(int id)
    {
        var token =         


        
5条回答
  •  耶瑟儿~
    2021-02-15 17:13

    You can pass multiple parameters in as URL as below example

    Parameter name must be the same (case-insensitive), If names do not match then values of the parameters will not be set.

    [HttpPost]
    [Route("{surveyId}/{expiryDate}")]
    public IActionResult Post(int surveyId, DateTime expiryDate)
    {
        return Ok(new { surveyId, expiryDate });
    }
    

    Call URL

    http://localhost:[port]/api/[controller]/1/3-29-2018
    

提交回复
热议问题