<p>I need a dropdown list on my page that will allow a user to select their state.  Since this is probably a control that will be used elsewhere, I thought it would be a good idea to create an MVC View User Control that could be reused.</p>

<p>I was thinking the control would look something like this:</p>

<pre><code>&lt;select name="" id=""&gt;
   &lt;option value="AL"&gt;Alabama&lt;/option&gt;
   &lt;option value="AK"&gt;Alaska&lt;/option&gt;
&lt;/select&gt;
</code></pre>

<p>And the code in my view would be something like:</p>

<pre><code>&lt;%= Html.RenderPartial("StateDropdownControl") %&gt;
</code></pre>

<p>My question is, what's the best way to set the name and id on the control?  I'd want to make sure I could have multiple instances of this control on one page, if needed.  Also, I'd want to be able to send in the state that should be selected by default.</p>

<p>Would I do it with ViewData somehow?</p>

Well you can pass object data to the RenderPartial method in conjunction to the User Control to render, so you could easily do the following:
```
```
```
```
<%= Html.RenderPartial("/someDirectory/SomeControl.ascx", "MyID") %>
```
```
and in the UserControl do the following:
```
```
<select name="<%=ViewData.Model%>" id="<%=ViewData.Model%>">

....
```
```
Just to be sure, a better way to handle it is to make a simple DTO (data transfer object) to hold that information so you can pass more information to your user control, that you will inevitably need.
Example:
```
```
class ComboData 
{
   string ID {get;set;}
   string CssClass {get;set;}
   //Other stuff here
}
```
```
```
```
<%
var comboData = new ComboData {ID = "myID", CssClass = "comboStyle" }

%>

<%= Html.RenderPartial("/someDirectory/SomeControl.ascx", comboData) %>
```
```
```
<select name="<%=ViewData.Model.ID%>" id="<%=ViewData.Model.ID%>" class="<%=ViewData.Model.CssClass%>">

....
```
Make sure you set the Code behind for the user control to be a generic of type ComboData for this example.