How can we hide a property in WebAPI?

There's good practice to use View Models for all GET/POST requests. In you case you should create class for receiving data in POST:

public class InsertDeviceViewModel
{        
    public string DeviceTokenIds { get; set; }
    public byte[] Data { get; set; }
    public string FilePwd { get; set; }        
}

and then map data from view model to you business model Device.


If you are using Newtonsoft.Json

you can hide the properties like this:

public class Product
{
    [JsonIgnore]
    public string internalID { get; set; };
    public string sku { get; set; };
    public string productName { get; set; };
}

and your serialized response will not include the internalID property.


I just figured out

[IgnoreDataMember]
 public int DeviceId { get; set; }

The namespace is System.Runtime.Serialization

More information IgnoreDataMemberAttribute Class

Learnt something new today.

Thanks All.