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);
}
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..
Surendra singhPosted Feb 28, 2015, 12:02 AM
you can use following link as reference.
http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application
Hope it will help you.