---
title: "How to select object in list asp.net?"  
description: "How to select object in list asp.net?"  
author: "Anonymous User"  
published: 2014-11-10  
updated: 2014-11-11  
canonical: https://www.mindstick.com/forum/2554/how-to-select-object-in-list-asp-dot-net  
category: "asp.net"  
tags: ["c#", "asp.net mvc", "mvc4"]  
reading_time: 1 minute  

---

# How to select object in list asp.net?

I'm beginer in [ASP NET](https://www.mindstick.com/forum/12814/asp-net-mvc-5-and-listbox-with-linq) and I don't know how to [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) object from list for exemple i have [static](https://www.mindstick.com/articles/12098/the-static-keyword-the-static-methods) [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) in my [model](https://yourviews.mindstick.com/view/81334/america-is-reopening-after-corona-lockdown-but-on-swedish-model):

```
namespace ProjectMVC.Models{    public class Initializer    {        public List<Profile> GetProfiles()        {            var profile = new List<Profile>(){                new Profile {                    Id = 1,                    Name = "Rohit",                    SportType = "Spount",                    Location = "allahabad"                },                new Profile {                    Id = 2,                    Name = "Pawan",                    SportType = "Spount",                    Location = "allahabad"                },                new Profile {                    Id = 3,                    Name = "Kamlakar",                    SportType = "Spount",                    Location = "allahabad"                },            };            return profile;        }    }
```

And i have [ajax request](https://www.mindstick.com/forum/157891/what-is-the-role-of-the-jsonresult-class-in-mvc-how-can-it-use-to-return-data-to-an-ajax-request) wich send an Id of [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server). For this I have [actionresult](https://www.mindstick.com/forum/33961/what-is-the-difference-between-actionresult-and-viewresult) in [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc):

```
namespace ProjectMVC.Controllers{    public class HomeController : Controller    {        private readonly Initializer init = new Initializer();       public ActionResult AddUserAjax(int UserId)        {          List<Profile> SomeList = init.GetProfiles();// here i want to select and return user from list , where UserId == Id from list in model           }}
```

## Replies

### Reply by Anonymous User

This should do:

var user = SomeList.FirstOrDefault(u => u.Id == UserId)

It's utilizing LINQ which is very powerful for querying objects.


---

Original Source: https://www.mindstick.com/forum/2554/how-to-select-object-in-list-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
