Using [Bind(Exclude='ID')] in DNX 5 with no System.Web

86 views Asked by At

I've read that you can use:

[Bind(Exclude="id")]

to stop an ID field from invalidating a ModelState when creating a record from a 'Create' action.

With DNX Core 5 System.Web is no longer available. Is there an equivalent way to ignore an auto-generated ID or am I in the same boat as this answer:

https://stackoverflow.com/a/34847744/2591770

UPDATE It seems as though items can be removed from the ModelState directly as described here: https://stackoverflow.com/a/13169910/2591770

I'm still interested in any other alternatives.

1

There are 1 answers

1
Chris Pratt On BEST ANSWER

Use a view model and then map the posted values to an instance of your entity. That way, only the properties you place on the view model may be modified. Bind is an anti-pattern anyways.