IgnoreDataMember .NET Core Web Api

Sami C.
1 min readJan 13, 2020

--

When applied to the member of a type, specifies that the member is not part of a data contract and is not serialized.

public class PersonViewModel{     public int Id { get; set; }     public string Name { get; set; }     [IgnoreDataMember]     public int Car_Id { get; set; }
}

The following request would suffice when using a PUT statement to update the record:

{
"Id": 1,
"Name": "Bob"
}

You can fill the id later on in the controller and still maintain one viewmodel.

In my case I had to fill the id from a user claim which was not exposed to the frontend.

Cheers!

--

--

Sami C.
Sami C.

Written by Sami C.

Freelance Software Engineer

No responses yet