I have created the hello world of ASP.NET MVC web API projects using VS2012:
public class ValuesController : ApiController
{
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
public string Get(int id)
{
return "value";
}
}
Issuing a get request to that controller returns some XML of the data with status 200. All good so far.
When I remove that method, like this:
public class ValuesController : ApiController
{
// GET api/values
//public IEnumerable<string> Get()
//{
// return new string[] { "value1", "value2" };
//}
// GET api/values/5
public string Get(int id)
{
return "value";
}
}
I then get a 404 not found. What I want is a 400 bad request, because an ID must be provided. How can I achieve this?