I am working at an ASP.NET MVC Web Api controller, and I am just a beginner so maybe my question is quite trivial...
I'd like to take a parameter named $filter
as input to my controller's method:
[Route("List")]
[HttpGet]
public IHttpActionResult List([FromUri] string $filter = null)
{
// ... code here ...
return (Ok());
}
However I can't do like that, because $filter
is not a valid C# variable name!
Anyway (due to customer requests) I really need to invoke that method passing $filter=something
in the URI...
How can I do? Is there a method to "map" the naming of URI parameters, so that in code I can use the variable name filter
(without the dollar) and then instructing the MVC layer to map $filter
onto filter
?
Set the Name
property of FromUriAttribute
:
[Route("List")]
[HttpGet]
public IHttpActionResult List([FromUri(Name = "$filter")] string filter = null)
{
// ... code here ...
return (Ok());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.