ASP.NET Core web api action selection based on Accept header

后端 未结 2 1291
遥遥无期
遥遥无期 2020-12-10 03:29

I want to return two different formatted responses for the same feature (a list of entities) based on the accept header of the request, it is for a \"json\" and a \"html\" r

2条回答
  •  感动是毒
    2020-12-10 04:06

    if(Request.Headers["Content-Type"] == "application/json")
    {
        return OK(json);
    }
    else
    {
        return View();
    }
    

    Thats ok?

提交回复
热议问题