---
title: "How to get id from dropdownlist?"  
description: "How to get id from dropdownlist?"  
author: "Anonymous User"  
published: 2014-01-22  
updated: 2014-01-23  
canonical: https://www.mindstick.com/forum/1862/how-to-get-id-from-dropdownlist  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to get id from dropdownlist?

I have such list

[public](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) IList<SelectListItem> ToCountryList { get; set; }

I have such line in the [razor view](https://www.mindstick.com/forum/155820/how-to-generate-textbox-control-using-htmlhelper-in-razor-view)

@Html.DropDownListFor(m => m.Filter.ToCountryId, Model.ToCountryList, string.Empty, new { [style](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment) = "min-width: 100px; width:180px" })

Now i want with juery to [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) ToCountryId from the [selected value](https://www.mindstick.com/forum/525/get-selected-value-of-datagridviewcomboboxcolumn) of [dropdownlist](https://www.mindstick.com/articles/324837/how-to-bind-dropdownlist-in-mvc-core-from-database-using-entity-framework) .How to get it ?

Such thing gives nothing

$("select[name='Filter.ToCountryId'] [option](https://www.mindstick.com/forum/159391/jquery-get-selected-option-from-dropdown):selected").val()

html from [browser](https://www.mindstick.com/blog/155254/which-is-the-best-internet-browser) (not sure how to publush - so plain text)

..select starts

select id="Filter_ToCountryId" name="Filter.ToCountryId" style="min-width: 100px; width:180px"

option tags with countries

..select ends

Guys, I need an id of the record.

For example - I have a pair ID-NAME 5-USA. So i need to [retrieve](https://www.mindstick.com/forum/34400/how-to-retrieve-form-values-in-controller-action) 5 (int)

## Replies

### Reply by Pravesh Singh

Hi Ankita,\

Just give your dropdown a deterministic id:

```
@Html.DropDownListFor(    m =>m.Filter.ToCountryId,    
Model.ToCountryList,     string.Empty,     new { id ="myddl", style = "min-width: 100px; width:180px" })
```

and then you could easily get the selected value using an id selector:

$('#myddl').val()


---

Original Source: https://www.mindstick.com/forum/1862/how-to-get-id-from-dropdownlist

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
