The parameter dictionary contains a null entry for the parameter "testId" of a non-zero type, "System.Int32"

I am trying to trigger an action in the controller:

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

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

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

+4
source share
1 answer

It looks like you are trying to map a default route that:

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

To do this, change the parameter name in ActionResult to id :

 public ActionResult Details(int id) 

Otherwise, you have to use the url:

  http://localhost:5345/ManageTest/Details?testId=5 
+9
source

All Articles