Q: Json return code to simplify if possible 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);
        }


A: This is how I make my jQuery ajax and webmethods:
Webmethod:
[WebMethod]
public object populatePgSubCategory(string catId)
{
    StoreDataContext db = new StoreDataContext();

    var a = from n in db.SubCategories
            where n.CategoryID == int.Parse(catId)
            orderby n.SubCategoryName
            select new
            {
                x = n.SubCategoryName,
                y= n.SubCategoryID
            };
        return a;   
}

jQuery ajax:
$.ajax({
            type: "POST",
            url: "/WebService_VehicleDisplay.asmx/populatePgSubCategory",
            data: "{catId:"+"'"+n+"'"+"}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                var response = msg.d;
                $("#ddlSubCat").empty();
                $.each(response, function (key,val) {
                    $('#ddlSubCat').append(new Option(val.x, val.y));
                });
            },
            failure: function (msg) {
                alert('failure');
            }
        });


A: The second part, where you build up the json-data can be simplified by using as json-serializer. I use Json.Net. This serializer automatically reads and writes JSON for a class. 
I don't fully get what you are exactly doing in the code you try te simplify, but when you replace your code with data = JsonConvert.SerializeObject(repository) you would be a step in the right direction, I guess
