By the url ~/Student/Details/5
being: (~: site root, Student: Controller, Details: Action, 5: student id), it is possible to retrieve the student by its id.
// GET: Student/Details/5
public ActionResult Details(int? id)
{
// it good practice to consider that things could go wrong so,it is wise to have a validation in the controller
if (id == null)
{
// return a bad request
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Student student = db.Students.Find(id);
if (student == null)
{
// if doesn't found return 404
return HttpNotFound();
}
return View(student);
}