My update phase in #dal
public int UpdateOrEditEmployee(string propertyName,string value, int empid)
{
try
{
using (AdventureWorksEntities empDbentity = new AdventureWorksEntities())
{
var status = false;
var message = "";
var users = empDbentity.tblEmployees.Find(empid);
if(users!=null)
{
empDbentity.Entry(users).Property(propertyName).CurrentValue = value;
empDbentity.SaveChanges();
status = true;
}
else
{
message = "Error!";
}
#bal public int UpdateOrEditEmployee(string value,int empid,string propertyName)
{
try
{
return empdata.UpdateOrEditEmployee(propertyName, value, empid);
}
catch(Exception ex)
{
throw ex;
}
}
#controller
[HttpPost]
public ActionResult UpdateOrEditEmployee(string propertyName,string value, int id)
{
var status=false;
var message="";
try
{
EmployeeBusiness EmpBusiness = new EmployeeBusiness();
var empid = EmpBusiness.UpdateOrEditEmployee(propertyName, id, value);
var response = new { value = value, status = status, message = message };
JObject o = JObject.FromObject(response);
return Content(o.ToString());
return View();
}
#View for the grid
@using PagedList;
@using PagedList.Mvc;
@model IPagedList
@{
Layout = null;
ViewBag.Title = "EmployeeDetails";
}
.Delete{
color:green;
}
.table td{
width:25%;
}
Registered Employess
| EmpLoyee ID | Employee Name | Designation | Employee Image | Salary | Department | ||
|---|---|---|---|---|---|---|---|
| @Html.DisplayFor(model => item.Empid, new { data_id = "@item.Empid", data_propertyname = "EmpId", @class = "edit" }) | @Html.DisplayFor(model => item.Empname, new { data_id = "@item.Empid", data_propertyname = "EmpName", @class = "edit" }) | @Html.DisplayFor(model => item.Designation, new { data_id = "@item.Empid", data_propertyname = "Designation", @class = "edit" }) | @{ var base64 = Convert.ToBase64String(item.ImageData); var imagesrc = string.Format("data:image/jpeg;base64,{0}", base64); } | @Html.DisplayFor(model => item.Salary, new { data_id = "@item.Empid", data_propertyname = "Salary", @class = "edit" }) | @Html.DisplayFor(model => item.Email, new { data_id = "@item.Empid", data_propertyname = "Email", @class = "edit" }) | @Html.DisplayFor(model => item.Department, new { data_id = "@item.Empid", data_propertyname = "Department", @class = "edit" }) |
@Html.PagedListPager(Model, page => Url.Action("EmployeeDetails", new { page }))
@section scripts{--------this is the section iam using for editing the cell but its not hitting can anyone help?
$(document.ready(function () {
debugger;
$("#EmpTable").on('click','.Delete',(function () {
debugger;
var empID = $(this).attr('data-id');
var oldValue='';
$('.edit').editable('/Employee/UpdateOrEditEmployee?id='+empID, {
cssclass: 'jeditForm',
tooltip: 'Click to edit me....',
width: 'none',
height: 'none',
onsubmit: function (settings, original) {
oldValue = original.revert;
},
submitdata: function () {
return {
id: $(this).data('Empid'),
PropertyName:$(this).data('propertyname')
}
},
callback: function (value,settings) {
var jsonData = $.parseJSON(value);
if (jsonData.status) {
$(this).text(jsonData.value);
}
else {
$(this).text(oldValue);
}
}
})
}))
}))
}
$(document).ready(function () {
$("#EmpTable").on('click','.Delete',(function () {
debugger;
var empID = $(this).attr('data-id');
window.location.href = "/Employee/DeleteEmployee?empid=" + empID;
}));
$("#btnback").click(function () {
debugger;
window.location.href = '@Url.Action("Employee", "Employee")';
});
})
Replies
Know the answer? Post it — somebody with the same question will find it here.