How to create simple mvc CRUD in asp.net using jsonSSsachin sheth10yAsked Feb 23, 2016, 7:51 AM EST3 answersShareLinkedInXCopy linkSave3 AnswersKnow the answer? Post it. Somebody with the same question will find it here.SSsachin sheth32 points10y agoPosted Feb 23, 2016, 7:54 AM EST0http://www.c-sharpcorner.com/UploadFile/cd7c2e/implement-insert-update-and-delete-functionality/ http://kushonline.blogspot.in/2015/02/insert-delete-update-retrieve-data-with.html0SSsachin sheth32 points10y agoPosted Feb 23, 2016, 8:07 AM EST0 Student Details Student Name: Address: Edit Name Address Delete 0SSsachin sheth32 points10y agoPosted Feb 23, 2016, 8:08 AM EST0using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;namespace MvcCrud.Controllers{ public class HomeController : Controller { public TraineeDemoEntities edc = new TraineeDemoEntities(); public ActionResult index() { return RedirectToAction("Employee"); } public ActionResult Employee() { return View(); } public string SaveEmployee(decimal id, string Name, string Address) { string msg = ""; if (id == 0) { var e1 = new Student(); e1.Name = Name; e1.Address = Address; e1.Isactive = 1; edc.Students.AddObject(e1); msg = "Insert Successfully "; edc.SaveChanges(); } else { Student s1 = edc.Students.SingleOrDefault(t => t.Sid == id); s1.Name = Name; s1.Address = Address; s1.Isactive = 1; msg = "Update Successfully"; edc.SaveChanges(); } return msg; } public JsonResult EditStudent(decimal id) { var objstud = edc.Students.Where(t => t.Sid == id).ToList(); return Json(objstud, JsonRequestBehavior.AllowGet); } public JsonResult BindStudent() { var objstud = edc.Students.Where(t => t.Isactive == 1).ToList(); return Json(objstud, JsonRequestBehavior.AllowGet); } public string DelStudent(int id) { string flg = ""; try { Student objstu = edc.Students.Where(t => t.Sid == id).SingleOrDefault(); if (objstu != null) { objstu.Isactive = 0; edc.SaveChanges(); flg = "true"; } } catch (Exception ex) { throw ex; } return flg; } }}0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign in
How to create simple mvc CRUD in asp.net using jsonSSsachin sheth10yAsked Feb 23, 2016, 7:51 AM EST3 answersShareLinkedInXCopy linkSave
SSsachin sheth32 points10y agoPosted Feb 23, 2016, 7:54 AM EST0http://www.c-sharpcorner.com/UploadFile/cd7c2e/implement-insert-update-and-delete-functionality/ http://kushonline.blogspot.in/2015/02/insert-delete-update-retrieve-data-with.html0
SSsachin sheth32 points10y agoPosted Feb 23, 2016, 8:07 AM EST0 Student Details Student Name: Address: Edit Name Address Delete 0
SSsachin sheth32 points10y agoPosted Feb 23, 2016, 8:08 AM EST0using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;namespace MvcCrud.Controllers{ public class HomeController : Controller { public TraineeDemoEntities edc = new TraineeDemoEntities(); public ActionResult index() { return RedirectToAction("Employee"); } public ActionResult Employee() { return View(); } public string SaveEmployee(decimal id, string Name, string Address) { string msg = ""; if (id == 0) { var e1 = new Student(); e1.Name = Name; e1.Address = Address; e1.Isactive = 1; edc.Students.AddObject(e1); msg = "Insert Successfully "; edc.SaveChanges(); } else { Student s1 = edc.Students.SingleOrDefault(t => t.Sid == id); s1.Name = Name; s1.Address = Address; s1.Isactive = 1; msg = "Update Successfully"; edc.SaveChanges(); } return msg; } public JsonResult EditStudent(decimal id) { var objstud = edc.Students.Where(t => t.Sid == id).ToList(); return Json(objstud, JsonRequestBehavior.AllowGet); } public JsonResult BindStudent() { var objstud = edc.Students.Where(t => t.Isactive == 1).ToList(); return Json(objstud, JsonRequestBehavior.AllowGet); } public string DelStudent(int id) { string flg = ""; try { Student objstu = edc.Students.Where(t => t.Sid == id).SingleOrDefault(); if (objstu != null) { objstu.Isactive = 0; edc.SaveChanges(); flg = "true"; } } catch (Exception ex) { throw ex; } return flg; } }}0
sachin sheth32 pointsPosted Feb 23, 2016, 7:54 AM EST
sachin sheth32 pointsPosted Feb 23, 2016, 8:07 AM EST
Student Details
Student Name:
Address:
Edit
Name
Address
Delete
sachin sheth32 pointsPosted Feb 23, 2016, 8:08 AM EST
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcCrud.Controllers
{
public class HomeController : Controller
{
public TraineeDemoEntities edc = new TraineeDemoEntities();
public ActionResult index()
{
return RedirectToAction("Employee");
}
public ActionResult Employee()
{
return View();
}
public string SaveEmployee(decimal id, string Name, string Address)
{
string msg = "";
if (id == 0)
{
var e1 = new Student();
e1.Name = Name;
e1.Address = Address;
e1.Isactive = 1;
edc.Students.AddObject(e1);
msg = "Insert Successfully ";
edc.SaveChanges();
}
else
{
Student s1 = edc.Students.SingleOrDefault(t => t.Sid == id);
s1.Name = Name;
s1.Address = Address;
s1.Isactive = 1;
msg = "Update Successfully";
edc.SaveChanges();
}
return msg;
}
public JsonResult EditStudent(decimal id)
{
var objstud = edc.Students.Where(t => t.Sid == id).ToList();
return Json(objstud, JsonRequestBehavior.AllowGet);
}
public JsonResult BindStudent()
{
var objstud = edc.Students.Where(t => t.Isactive == 1).ToList();
return Json(objstud, JsonRequestBehavior.AllowGet);
}
public string DelStudent(int id)
{
string flg = "";
try
{
Student objstu = edc.Students.Where(t => t.Sid == id).SingleOrDefault();
if (objstu != null)
{
objstu.Isactive = 0;
edc.SaveChanges();
flg = "true";
}
}
catch (Exception ex)
{
throw ex;
}
return flg;
}
}
}