Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 785867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:56:51+00:00 2026-05-14T20:56:51+00:00

What is the best way to return only few properties to JSON Result from

  • 0

What is the best way to return only few properties to JSON Result from a collection IEnumerable?

Department object has 7properties I only need to 2 of them in 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);

        //Department object has 15 properties, I ONLY need 2 (DeptID and DeptName) in the view via returns JSON result)


        return Json(depts, JsonRequestBehavior.AllowGet); // I don’t want all the  properties of  a department object
   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:56:52+00:00Added an answer on May 14, 2026 at 8:56 pm
    var deptnames = depts.Select(d => new { d.DeptID, d.DeptName });
    

    Then just use deptnames

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the best way to return a Java Map using the JSON format? My
What is the best way to return the result of the execution of a
Considering the tables below, what is the best way to only return the team
What is the best way if i would like to only return :id and
What would be the best way to detect newline return method in PHP. CR,
What's the fastest/best way to compare two arrays and return the difference? Much like
What is the best way to disable UITextField's 'return' keyboard key if input area
What's the best way to print from MySQL using PHP when you know there's
What's the best way to trim a DateTime object to a specific precision? For
Best way to match 2 pages for Google analytics. Pages to Query: 1.) this_google.html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.