mercredi 1 juillet 2015

How to get Max(ID) from Student and Create in MVC

I am using one MVC example in which ID is incremental in database. To create the record it is like: But in my case ID in Student table is not incremental, I need to get MAX(ID) from Student table.

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ID,LastName,FirstMidName,EnrollmentDate,CountryID,Account_Code")] Student student)
{
    if (ModelState.IsValid)
    {
        db.Students.Add(student);
        db.SaveChanges();
        return RedirectToAction("Index");
    }
    return View(student);
}

I want to remove "ID" from my Include and want to get MAX(ID) from Student table through LINQ and save it to the table. Please help me thanks

Aucun commentaire:

Enregistrer un commentaire