@grid.GetHtml(
tableStyle: "grid",
columns: grid.Columns(
grid.Column("Name"),
grid.Column("Address"), grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.Value.ID })), grid.Column(format: (item) => Html.ActionLink("Delete", "Delete", new { id = item.Value.ID })), grid.Column("Class")
)
)
public class HomeController : Controller
{
entityFrameworkDataEntities obj = new entityFrameworkDataEntities();
public ActionResult Index()
{
var Result = from C in obj.TblDetails
select C;
ViewBag.webgriddata = Result.ToList();
List abc = new List(2);
var q = from a in obj.TblDepts
select a;
foreach (var i in q)
{
abc.Add(i.Dept);
}
ViewBag.Names = abc;
return View(q);
}
public ActionResult About(string val)
{
return View();
}
public ActionResult CategoryDetails(string Id)
{
int id = (from d in obj.TblDepts
where d.Dept == Id
select d.Id).FirstOrDefault();
var Result = from C in obj.TblDetails
where C.DeptID == id
select C;
ViewBag.webgriddata = Result.ToList();
List abc = new List(2);
var q = from a in obj.TblDepts
select a;
foreach (var i in q)
{
abc.Add(i.Dept);
}
ViewBag.Names = abc;
return View("Index");
}
public ActionResult Edit(int id)
{
TblDetail obj2 = new TblDetail();
var dd = getdata(id);
obj2.Address = dd.Address;
obj2.Class= dd.Class;
obj2.Name = dd.Name;
obj2.DeptID = dd.DeptID;
return View(obj2);
}
[HttpPost]
public ActionResult edit(TblDetail model)
{
TblDetail obj2 = new TblDetail();
obj2.ID = model.ID;
obj2.Address = model.Address;
obj2.Class = model.Class;
obj2.Name = model.Name;
obj2.DeptID = model.DeptID;
obj.TblDetails.Attach(obj2);
obj.ObjectStateManager.ChangeObjectState(obj2, System.Data.EntityState.Modified);
obj.SaveChanges();
return RedirectToAction("index");
}
public TblDetail getdata(int id)
{
entityFrameworkDataEntities obj = new entityFrameworkDataEntities();
var dd = from e in obj.TblDetails
where e.ID == id
select e;
return dd.FirstOrDefault();
}
public ActionResult Delete(int id)
{
TblDetail obj2 = new TblDetail();
TblDetail Product = (from c in obj.TblDetails
where c.ID == id
select c).FirstOrDefault();
obj.TblDetails.DeleteObject(Product);
obj.SaveChanges();
return RedirectToAction("index");
}
}
}