Json return code to simplify if possible.
Posted
by
pirzada
on Stack Overflow
See other posts from Stack Overflow
or by pirzada
Published on 2010-12-27T05:19:10Z
Indexed on
2010/12/27
8:53 UTC
Read the original article
Hit count: 249
jquery-ajax
|asp.net-mvc-3
Can you simplify this code?. Is there anything we can do to make it more simple. I am not sure but it looks ugly to me.
[HttpPost]
public JsonResult UserDetailById(int userId, string username)
{
IQueryable<Company> repository = companyRepository.GetGridCompanies();
Employee emp = companyRepository.GetEmployee(userId);
//Drop down fill
var a = (from c in repository
.OrderBy(c => c.companyName)
select new
{
Id = c.companyID,
Name = c.companyName
}).ToArray();
var data = new
{
Id = emp.companyID.ToString(),
Name = emp.employeeFirstname + " " + emp.employeeLastname,
Fn = emp.employeeFirstname,
Ln = emp.employeeLastname,
Dept = emp.employeeDepartment,
Sup = emp.employeeSup.ToString(),
HireDate = String.Format("{0:MM/dd/yyyy}", emp.employeeHiredate),
CompVm = a
};
return Json(data);
}
© Stack Overflow or respective owner