Ниже приведен фрагмент кода из моего StudentController.
Код: Выделить всё
public ActionResult Edit(int studentId)
{
var std = studentList.Where(s => s.StudentId == studentId).FirstOrDefault();
return View(std);
}
[HttpPost]
public ActionResult Edit(Student std)
{
//write code to update student
return RedirectToAction("Index");
}
Код: Выделить всё
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Код: Выделить всё
The parameters dictionary contains a null entry for parameter 'studentId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Edit(Int32)' in 'MVC1.Controllers.StudentController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
Но он работает нормально, когда я нажимаю URL-адрес http://localhost:54976/student/Edit?StudentId=1.
Я новичок в .net MVC. Может ли кто-нибудь подсказать мне это?
Подробнее здесь: https://stackoverflow.com/questions/450 ... e-declared