Bind from any request input: FromQuery, FromRoute, FromForm

Viewed 1490

In ASP.NET Core, I need the ViewModel members to be data bound to the incoming request data. I don't care if it comes from Form post, Query string or Route param.

It seems there are new attributes for each of these sources, but not one that handles them all.

[FromQuery(Name="xyz")] // Works only with query string
[FromForm(Name="xyz")] // Works only with form data
[FromRoute(Name="xyz")] // Works only with route data
public string Something {get; set;}

Is there any way to support all of them?

1 Answers

Unfortunately, no. The declaration is explicit. You must choose to take it from the query string, the request body, or the URL.

Related