Should I return IList or List to the Controller in MVC?

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error Should I return IList or List to the Controller in MVC? on this date .

What is difference to the controller that gets the return with repect to rendering the List?

In Linq dataContext:

public IList<Response> GetResponses(int ID)
    {
        var responses = from r in this.Responses where r.ID == ID orderby r.Date select r;

        return responses.ToList();
    }

OR

 public List<Response> GetResponses(int ID)
    {
        var responses = from r in this.Responses where r.ID == ID orderby r.Date select r;

        return responses.ToList();
    }

Answer

I doubt there’s much difference to the controller but you should probably try to reveal as little information as possible about the private data of your classes. This means exposing interfaces rather than concrete types and using the interface that exposes the minimum amount of information the client will need to operate on the data.

If the controller only needs an IEnumerable<Response> then you should consider making that the return type of GetResponses.