Consider the following 2 controllers. One is a Web API controller and the other an MVC controller.
```
public class ValuesController : ApiController
{
[System.Web.Http.Route("api/values/{category?}")]
public string Get(int category)
{
return "value:" + category;
}
}
public class HomeController : Controller
{
[System.Web.Mvc.Route("Home/Index/{category?}")]
public ActionResult Index(int category)
{
return Content("Home.Index:" + category);
}
}
```
__Status of Requests__:
GET /api/values -> Succeeds and prints "value:0"
GET /Home/Index -> __Fails__ with 500 Internal Server Error.
__Exception__:
```
The parameters dictionary contains a null entry for parameter 'category' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32)' in 'RuntimeWebApp.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: The parameters dictionary contains a null entry for parameter 'category' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32)' in 'RuntimeWebApp.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
```
__FYI__:
In Web API's attribute routing, we add a custom route called HttpDirectRoute in which we handle situation like this.
__Expected__:
Provide an experience which is similar to Web API. I am thinking we could minimize regresion if we provide this behavior only for attributed controllers/actions just like how Web API does.
Comments: The Web API behavior seems incorrect - the Web API action has a required parameter that isn't present.
```
public class ValuesController : ApiController
{
[System.Web.Http.Route("api/values/{category?}")]
public string Get(int category)
{
return "value:" + category;
}
}
public class HomeController : Controller
{
[System.Web.Mvc.Route("Home/Index/{category?}")]
public ActionResult Index(int category)
{
return Content("Home.Index:" + category);
}
}
```
__Status of Requests__:
GET /api/values -> Succeeds and prints "value:0"
GET /Home/Index -> __Fails__ with 500 Internal Server Error.
__Exception__:
```
The parameters dictionary contains a null entry for parameter 'category' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32)' in 'RuntimeWebApp.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: The parameters dictionary contains a null entry for parameter 'category' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(Int32)' in 'RuntimeWebApp.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
```
__FYI__:
In Web API's attribute routing, we add a custom route called HttpDirectRoute in which we handle situation like this.
__Expected__:
Provide an experience which is similar to Web API. I am thinking we could minimize regresion if we provide this behavior only for attributed controllers/actions just like how Web API does.
Comments: The Web API behavior seems incorrect - the Web API action has a required parameter that isn't present.