Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The parameters dictionary contains a null entry for parameter 'testId' of non-nullable type 'System.Int32'

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

like image 891
Elad Benda Avatar asked Dec 26 '22 05:12

Elad Benda


1 Answers

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
like image 60
mattytommo Avatar answered Feb 13 '23 22:02

mattytommo