Users Pricing

forum

Home Forums Dropdownlist selected value in asp.net mvc – MindStick

Dropdownlist selected value in asp.net mvc

Manoj Bhatt 2501 08 Oct 2014
 have tried this is RC1 and then upgraded to RC2 which did not resolve the issue.
// in my controller
        ViewData["UserId"] = new SelectList(
        users,
        "UserId",
        "DisplayName",
        selectedUserId.Value); // this has a value

result: the SelectedValue property is set on the object.

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

result: all expected options are rendered to the client, but the selected attribute is not set. The item in SelectedValue exists within the list, but the first item in the list is always defaulted to selected.


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md