How should I pass multiple parameters to an ASP.Net Web API GET?

前端 未结 11 1402
温柔的废话
温柔的废话 2020-12-12 09:59

I am using the .Net MVC4 Web API to (hopefully) implement a RESTful api. I need to pass in a few parameters to the system and have it perform some action, then return a lis

11条回答
  •  情歌与酒
    2020-12-12 10:40

        public HttpResponseMessage Get(int id,string numb)
        {
            //this will differ according to your entity name
            using (MarketEntities entities = new MarketEntities())
            {
              var ent=  entities.Api_For_Test.FirstOrDefault(e => e.ID == id && e.IDNO.ToString()== numb);
                if (ent != null)
                {
                    return Request.CreateResponse(HttpStatusCode.OK, ent);
                }
                else
                {
                    return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Applicant with ID " + id.ToString() + " not found in the system");
                }
            }
        }
    

提交回复
热议问题