Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Filter properties based on request HTTP method

$
0
0

What's the best way to customize model properties that will be bound depending on the request method used?

For example in the following model

public class User
{
  public int Id {get; set;}
  public string Name {get; set;}
}

property Id should be bound on Update (HTTP PUT) but ignored during Create (HTTP POST).

I looked into IPropertyFilterProvider but it uses ModelMetadata and probably won't give me any information about the current request.

The other option I see is creating a custom IModelBinder, but implementing interface from scratch seems redundant in this case. In case of using existing implementations which one should I select and where should it be inserted in the ModelBinderProviders pipeline so it won't break anything else (there are already 14 of them by default)?

I'm looking for generic solution where property-method mapping will be specified via attributes or some conventions.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>