What is the best way to return only a few properties to a JSON result from an IEnumerable collection?
The department object has 7properties. I need only 2 of them in the client. Can I do this using C # anonymous types?
public class Department { public string DeptId { get; set; } public string DeptName { get; set; } public string DeptLoc1 { get; set; } public string DeptLoc2 { get; set; } public string DeptMgr { get; set; } public string DeptEmp { get; set; } public string DeptEmp2 { get; set; } } [HttpGet] public JsonResult DepartmentSearch(string query) { IEnumerable<Department> depts = DeptSearchService.GetDepartments(query);
Spock source share