I want to follow proper URL convention and use hyphen as word delimiter: /api/books?author-id=3
But property names with hyphen are not supported in C#. How can I bind AuthorId
to author-id
in .NET Framework 4.8?
As an example, consider this URL: /api/books?authorid=3
It maps to the method below.
[RoutePrefix("api/books")]
public class BooksController
{
[HttpGet]
public async Task<IHttpActionResult> GetBooks([FromUri] GetBooksParameters getBooksParameters)
{
var authorId = getBooksParameters.AuthorId;
// ...
}
}
public class GetBooksParameters
{
public int? AuthorId { get; set; }
}