Your return value is not in right type...
Refer below samples...I am using Item class, which is having 3 properties
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
public double Price{ get; set; }
}
---------------------------------------------------------------
private IEnumerable<Item> items = new List<Item>()
{
new Item{Id=1,Name="Item1",Price=20.1},
new Item{Id=2,Name="Item2",Price=20.2},
new Item{Id=3,Name="Item3",Price=20.3}
};
public IHttpActionResult Get()
{
return Ok(items);
}
public IHttpActionResult Get(int iid)
{
return Ok(items.Where(x => x.Id == iid));
}
--------------------------------------------------------------
or
--------------------------------------------------------------
public IEnumerable<Item> Get()
{
return items.ToList();
}
public IHttpActionResult Get(int id)
{
var vitem=items.Where(x => x.Id == id);
if(vitem==null)
{
return NotFound();
}else
{
return Ok(vitem);
}
}
Refer below samples...I am using Item class, which is having 3 properties
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
public double Price{ get; set; }
}
---------------------------------------------------------------
private IEnumerable<Item> items = new List<Item>()
{
new Item{Id=1,Name="Item1",Price=20.1},
new Item{Id=2,Name="Item2",Price=20.2},
new Item{Id=3,Name="Item3",Price=20.3}
};
public IHttpActionResult Get()
{
return Ok(items);
}
public IHttpActionResult Get(int iid)
{
return Ok(items.Where(x => x.Id == iid));
}
--------------------------------------------------------------
or
--------------------------------------------------------------
public IEnumerable<Item> Get()
{
return items.ToList();
}
public IHttpActionResult Get(int id)
{
var vitem=items.Where(x => x.Id == id);
if(vitem==null)
{
return NotFound();
}else
{
return Ok(vitem);
}
}