0

How can I exclude Id field from response in controller?

Here is my model:

public class Dog
{

    public long Id { get; set; }
    public string Breed { get; set; }
    public string Image { get; set; }
}

Controller:

[HttpGet]
    public IEnumerable<Dog> GetDog()
    {
        //return from dog in _context.DogResponse select dog;
        return _context.Dog;
    }
  • Use `XmlIgnore` or `JsonIgnore` attribute depending on the output type. – mshsayem Jan 24 '18 at 11:15
  • 2
    you could use a DTO object which doesn't include fields you don't want to return. Most well-implemented web APIs don't directly return the DB model objects to the client. – ADyson Jan 24 '18 at 11:17

0 Answers0