hersh
hersh

Reputation: 1183

dropdownlist issue

I have a dropdownlist generated from db. Here is the result from page source.

<select id="testList" name="testList">
<option value="0"></option>
<option value="0">A</option>
<option value="1">B</option>
</select>

Does anyone know why the empty is still zero? How come I dont get something like "" for the first one since it's empty?

<div class="editor-field">
<%= Html.DropDownList("list") %>
</div>

ViewData["list"] = new SelectList(list, "Id", "Value");

Upvotes: 0

Views: 54

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039438

Because I suppose that you have used a value type such as Int32 for the Id property. Try using a nullable integer instead: int?

Upvotes: 4

Related Questions