controller code
public class EmployeeController : Controller
{
LoginDB2Entities1 ld = new LoginDB2Entities1();
[HttpGet]
public ActionResult GetByEmployeeID()
{
return View();
}
[HttpPost]
public ActionResult GetByEmployeeID(int id)
{
using (LoginDB2Entities1 ldb = new LoginDB2Entities1())
{
var deptemp = from e in ldb.Depts
join o in ldb.Emps on e.Did equals o.Did
where e.Did == id
select new
{
o.Salary,
e.Did,
o.EmpId,
o.EmpName,
o.Empjob,
e.DName,
};
var empdetails = deptemp.FirstOrDefault();
return Json(new { empdetails });
}
}
public ActionResult DisplayAll()
{
var emp = ld.Emps.Include(a => a.Dept);
return View(emp.ToList());
}
}
}
view code
@{
ViewBag.Title = "GetByEmployeeID";
}
GetByEmployeeID
$(document).ready(function () {
$("#btnSubmit").click(function () {
var id = $("#txtId").val();
$.ajax({
type: "POST",
url: "/Employee/GetByEmployeeID",
contentType: "application/json;character=utf-8",
dataType: "json",
data: JSON.stringify({ "id": id }),
success: function (item) {
if (item != null) {
$("#did").val(item.empdetails.Did);
$("#dname").val(item.empdetails.Dname);
$("#empId").val(item.empdetails.EmpId);
$("#eName").val(item.empdetails.EmpName);
$("#eJob").val(item.empdetails.EmpJob);
$("#salry").val(item.empdetails.Salary);
}
else {
alert("Some error occur")
}
},
error:function(item){}
})
});
});
Ramesh PalanivelPosted Mar 23, 2018, 12:36 AM
Ramesh PalanivelPosted Mar 23, 2018, 12:50 AM
Gautam PuhanPosted Mar 23, 2018, 12:46 AM
Gautam PuhanPosted Mar 23, 2018, 12:40 AM