question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`BindNever`, `JsonIgnore`, and `BindRequired`

See original GitHub issue

When 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:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jaredcnancecommented, Feb 12, 2018

Ah, I see. So, there are 2 requirements currently not met:

  1. Allow read-only attributes which cannot be set on POST
  2. Improve portability of pre-existing models by supporting Newtonsoft attributes and ASP.Net model binding attributes

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.

0reactions
bart-degreedcommented, Sep 29, 2021

As mentioned earlier, we cannot propagate all custom attributes on resource properties. Our recent switch to System.Text.Json does not change that.

However:

  • We do provide AttrCapabilities, which enables devs to specify setting a value on POST and/or PATCH is not allowed.
  • We have working ASP.NET model state validation, so you can put [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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found