Shibly  Sadik

Shibly Sadik

  • NA
  • 167
  • 136.1k

Edit data in mvc entity framework database

Feb 27 2015 10:52 AM
I have created a database using mvc CRUD operation.My edit action is as below:
 
// GET: /Student/Edit/5
public ActionResult Edit(int id)
{

if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
MyStudent mystudent = db.mdb.Find(id);
if (mystudent == null)
{
return HttpNotFound();
}
return View(mystudent);
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include="Roll,Name,Dept,Gender,Phone")] MyStudent mystudent)
{
if (ModelState.IsValid)
{
db.Entry(mystudent).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(mystudent);
}
Now what i want to is to take the value of the parameter id through a textbox from user and perform the edition.
I'm  very beginner. Help me please..
 

Answers (1)