C# – The parameters dictionary contains a null entry for parameter ‘testId’ of non-nullable type ‘System.Int32’

asp.net-mvc, c++, web-services

I'm trying to call an action in my controller:

using this url:
http://localhost:5345/ManageTest/Details/5

[Authorize]public class ManageTestController : Controller{public ActionResult Details(int testId)    {

The parameters dictionary contains a null entry for parameter 'testId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Details(Int32)' in 'MAMAdmin.Controllers.ManageTestController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters

Best Solution

That looks like you're trying to map to the default route, which is:

RouteTable.Routes.MapRoute(            name: "Default",            url: "{controller}/{action}/{id}",            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });

To do that, change your parameter name in your ActionResult to be id:

public ActionResult Details(int id)

Otherwise you'd have to use the URL:

 http://localhost:5345/ManageTest/Details?testId=5