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

asp.net-mvc, c#

Solution

You are expecting an `id` parameter in your URL but you aren't supplying one. Such as:

http://yoursite.com/controller/edit/12
                                    ^^ missing

Problem

I am building My first MVC application, I have a table in database containing 3 columns: - Id → primary key - Username - password When I am clicking on edit link edit a record, its throwing following exception: The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Edit(Int32)' in 'MvcApplication1.Controllers.UserController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters Here is my edit code: ``` public ActionResult Edit(int id, User collection) { UserDBMLDataContext db = new UserDBMLDataContext(); var q = from abc in db.User_Login_Details where abc.Id == id select abc; IList lst = q.ToList(); User_Login_Details userLook = (User_Login_Details)lst[0]; userLook.Username = collection.UserName; userLook.Password = collection.Password; db.SubmitChanges(); return RedirectToAction("Index"); } ```

Original source