0

Request URL:http://localhost:51536/Employee/AddUpdateEmployee/2

Route Config

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

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

Controller Action Method

[ActionName("AddUpdateEmployee"), HttpGet]
public ActionResult AddUpdate(Int64 EmployeeID)
{
    var data = (new EmployeeDb()).GetEmployee(EmployeeID);
    return View("~/Views/Employee/_AddUpdateView.cshtml", data);
}

When I check the url in browser, i get this error: The parameters dictionary contains a null entry for parameter 'EmployeeID'

Pankaj
  • 9,749
  • 32
  • 139
  • 283

1 Answers1

0

this is because according to your route when you do /2 it thinks of it as value of /{id} means id but in action the parameter name is EmployeeID so it will be null

Solution 1:

public ActionResult AddUpdate(Int64 EmployeeID) 

change to

public ActionResult AddUpdate(Int64 id) 

Solution 2:

send values like

http://localhost:51536/Employee/AddUpdateEmployee?EmployeeID=2

Usman
  • 4,615
  • 2
  • 17
  • 33