`BindNever`, `JsonIgnore`, and `BindRequired`
See original GitHub issueWhen using the entity model as the resource model, it is useful to be able to use the BindNever
, JsonIgnore
, and BindRequired
attributes. This way you can easily specify which properties should be hidden from the client and how. As far as I know, you can’t do this with the current implementation (these attributes simply don’t work).
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
FromBody binds property with BindNever attribute
From the documentation about [Bind], [BindRequired], [BindNever] : These attributes affect model binding when posted form data is the source ...
Read more >ASP.Net Core Model binding
[BindRequired] : Can only be applied to model properties, not to method parameters; If binding cannot happen, this attribute adds a ModelState ...
Read more >Model Binding in ASP.NET Core
[BindNever] attribute. Can be applied to a property or a type. Prevents model binding from setting a model's property.
Read more >How to prevent mass assignment in ASP.NET Core
It explains when you should use [BindNever] attribute and how can you ... NET has [JsonIgnore] which could be used to prevent binding....
Read more >你所不知道的ASP.NET Core MVC/WebApi基础系列(二)
NET Core给我们提供了[BindRequired]、[BindNever]、[FromHeader]、[FromQuery]、[FromRoute]、[FromForm]、[ ... NET则属性忽略使用【JsonIgnore】。
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah, I see. So, there are 2 requirements currently not met:
POST
By implementing 2 we also implement 1. I think this will take a little bit of research to do properly. When I have time I’ll spec out the requirements for the implementation in this issue.
As mentioned earlier, we cannot propagate all custom attributes on resource properties. Our recent switch to System.Text.Json does not change that.
However:
AttrCapabilities
, which enables devs to specify setting a value on POST and/or PATCH is not allowed.[Required]
on properties. This works correctly when combined with partial patch. Note this is turned off by default.I believe these address the requested functionality, so I’m closing this. It does not enable reusing existing models with Newtonsoft or System.Text.Json annotations, but as explained earlier I don’t think we can solve that.