user833102
user833102

Reputation:

How to edit row with Webgrid Razor MVC3

Can a WebGrid be made editable?

Upvotes: 2

Views: 3980

Answers (1)

Yograj Pandey
Yograj Pandey

Reputation: 36

Make new View Edit.cshtml and take Hiddenfield for id that will pass to madel for the update data.

public ActionResult Edit(WebdridDBModel model, string id)
{          
    var editItem = from e in dc.EDetails where e.Id ==Convert.ToInt32(id) select e;
    var editList = editItem.ToList();
    model.FirstName= editList[0].FirstName;
    model.LastName=editList[0].LastName;
    model.Salary =Convert.ToInt32( editList[0].Salary);

    return View(model);
}




public ActionResult EditSubmit(WebdridDBModel model, string id)
{
    EDetail ed = dc.EDetails.Single(P=>P.Id==model.Id);
    ed.FirstName = model.FirstName.Trim();
    ed.LastName = model.LastName.Trim();
    ed.Salary = model.Salary.ToString();
    dc.SubmitChanges();
    return RedirectToAction("Index");
}

Upvotes: 2

Related Questions