Alex Rivera | Logout

MVC .NET Create Drop Down List from Model Collection in Strongly Typed view

Asked 2012-10-04T19:49:09.143
10

So I have a view typed with a collection like so:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IList<DTO.OrganizationDTO>>" %>

The OrganizationDTO looks like this:

public OrganizationDTO
{
    int orgID { get; set; }
    string orgName { get; set; }
}

I simply want to create a Drop Down List from the collection of OrganizationDTO's using an HTML helper but for the life of me I cant figure it out! Am I going about this the wrong way?

Should I be using a foreach loop to create the select box?

Edit
Report

1 Answer

5

Try this:

<%= Html.DropDownList("SomeName", new SelectList(Model, "orgID", "orgName"), "Please select Organization") %>
answered 2012-10-04T20:20:04.050

Your Answer