I am using ASP.NET Core and I have an API controller that has a POST action. The route is /categories/{categoryname}. The route parameter of categoryname is a string.
I am using Swagger UI. I want to be able to enter a string with spaces in it- for example: Executive Recruiter
Is there a way to do this?
CodePudding user response:
you can encode and decode your data for query string or route values
var s = "Executive Recruiter";
var encoded = Uri.EscapeDataString(s); // = Executive Recruiter
var decoded = Uri.UnescapeDataString(encoded); // = Executive Recruiter
but it is usually not needed to decode a string, controller decodes it automatically.
CodePudding user response:
The resolution was I removed the route on the Post Action. In the Swagger UI I dont need to add the . Here is what the controller looks like:
[HttpPost]
[ProducesResponseType(typeof(ConnectionCategoryModel), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[Consumes("application/json")]
public async Task<ActionResult<ConnectionCategoryModel>> AddConnectionCategoryAsync(int connectionManagerID, string categoryName)