I am curious why ApiController handles default parameter values ββfor actions differently than a "normal" controller.
This code works just fine, requesting / Test means the page is getting a value of 1
public class TestController : Controller
{
public ActionResult Index(int page = 1)
{
return View(page);
}
}
This code does not work when a request is made in / api / Values. He does not work:
"The parameter dictionary contains a null entry for the page parameter of the non-element type" System.Int32 "for the method" System.Collections.Generic.IEnumerable`1 [System.String] Get (Int32) 'in' MvcApplication1.Controllers.Controllers.ValuesController ' . The optional parameter must be a reference type, a null type, or declared as an optional parameter. "
public class ValuesController : ApiController
{
public IEnumerable<string> Get(int page = 1)
{
return new string[] { page.ToString() };
}
}
Any hints on why this is?