---
title: "Dropdownlist selected value in asp.net mvc"  
description: "Dropdownlist selected value in asp.net mvc"  
author: "Manoj Bhatt"  
published: 2014-10-08  
updated: 2014-10-08  
canonical: https://www.mindstick.com/forum/2332/dropdownlist-selected-value-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["asp.net", "asp.net mvc"]  
reading_time: 1 minute  

---

# Dropdownlist selected value in asp.net mvc

have tried this is RC1 and then upgraded to RC2 which did not [resolve the issue](https://answers.mindstick.com/qa/108575/how-to-resolve-the-issue-of-sign-up-in-the-mindstick-website).

```
// in my controller        ViewData["UserId"] = new SelectList(        users,         "UserId",         "DisplayName",         selectedUserId.Value); // this has a value
```

[result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency): the SelectedValue [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) is set on the object.\

```
// in my view        <%=Html.DropDownList("UserId", (SelectList)ViewData["UserId"])%>
```

result: all expected [options](https://www.mindstick.com/articles/43878/making-the-best-use-of-the-options-trade-ideas) are rendered to the [client](https://www.mindstick.com/articles/23198/3-steps-to-ensure-that-your-client-portal-is-impeccable), but the selected [attribute](https://www.mindstick.com/blog/221/attributes-reflection) is not set. The [item](https://www.mindstick.com/forum/156564/remove-item-in-an-array-in-javascript) in SelectedValue [exists](https://www.mindstick.com/forum/158947/how-do-you-use-the-exists-operator-to-check-for-the-existence-of-records-in-a-subquery) within the list, but the first item in the list is always defaulted to selected.\

## Replies

### Reply by Anonymous User

Try this:

```
public class Person        {            public int Id { get; set; }            public string Name { get; set; }        }
```

And then:\

```
var list = new[] {               new Person { Id = 1, Name = "Name1" },             new Person { Id = 2, Name = "Name2" },             new Person { Id = 3, Name = "Name3" }         };         var selectList = new SelectList(list, "Id", "Name", 2);        ViewData["People"] = selectList;         Html.DropDownList("PeopleClass", (SelectList)ViewData["People"])
```

With MVC RC2, I get.\

```
<select id="PeopleClass" name="PeopleClass">    <option value="1">Name1</option>    <option selected="selected" value="2">Name2</option>    <option value="3">Name3</option></select>
```


---

Original Source: https://www.mindstick.com/forum/2332/dropdownlist-selected-value-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
