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");
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…