How to return a list of objects as an IHttpActionResult?

前端 未结 4 1447
伪装坚强ぢ
伪装坚强ぢ 2021-02-08 09:19

I\'m new to ASP.NET webapi and I can\'t find a way to return a list of objects queried by id.

This is my controller method for the GET request. I want to return all the

4条回答
  •  醉酒成梦
    2021-02-08 09:51

    I think that you are looking for some code similar to below:

    public IEnumerable Get(int id)
        {
            //Create the list that you need to return here
            // I am creating a new list and adding an object below just for 
            // explaining the idea.
    
            var questions = new List();
            questions.Add(new Question());
            return questions;
        }
    

提交回复
热议问题