Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!
At view i have link: http://localhost:54149/Users/Delete/13
And controller:

SQL
public ActionResult Delete(int Idaccesso)
        {

            if (Idaccesso != null && Idaccesso != 0)
            {

}
}

This controller returns error:
The parameters dictionary contains a null entry for parameter 'Idaccesso' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Delete(Int32)' in 'CMSPI.Controllers.UsersController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters 

If it replace on:
<pre lang="sql">public ActionResult Delete(int Idaccesso = 0)
        {

            if (Idaccesso != null && Idaccesso != 0)
            {

}
}

Than only keep Idaccesso = 0, because Idaccesso set by default.
How will be?
Posted

1 solution

What's the MapRoute of your MvcApplication? Does it defined like this?


C#
public class MvcApplication : HttpApplication
{
    // ...

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",                      // Route name
            "{controller}/{action}/{id}",   // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
                
        );

    }

    //...

}

Try to change the parameter's name from Idaccesso to id.

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900