ASP.Net MVC RC DropDownList

  • Thread starter Thread starter cksanjose
  • Start date Start date
C

cksanjose

I'm trying out ASP.Net MVC (Release Candidate). I'm trying to render a
dropdownlist. My code below will not display a dropdownlist.

My controller has this code block:


var clients = from client in vetData.Clients
orderby client.ClientId
select client;


ViewData["clientlist"] = new SelectList(clients.ToList(),
"ClientId", "FirstName");

return View();

My view has this code block:
<tr>
<td>Client</td>
<td><%
var clients = ViewData["clientlist"] as
IEnumerable<SelectListItem>;
Html.DropDownList("clients", clients);
%></td>
 
cksanjose said:
I'm trying out ASP.Net MVC (Release Candidate). I'm trying to render a
dropdownlist. My code below will not display a dropdownlist.

My controller has this code block:


var clients = from client in vetData.Clients
orderby client.ClientId
select client;


ViewData["clientlist"] = new SelectList(clients.ToList(),
"ClientId", "FirstName");

return View();

My view has this code block:
<tr>
<td>Client</td>
<td><%
var clients = ViewData["clientlist"] as
IEnumerable<SelectListItem>;
Html.DropDownList("clients", clients);
%></td>

Html extension methods return strings, they don't actually write to the
response for you.

Response.Write(Html.DropDownList("clients", clients));
 
I'm trying out ASP.Net MVC (Release Candidate). I'm trying to render a
dropdownlist. My code below will not display a dropdownlist.
My controller has this code block:
           var clients = from client in vetData.Clients
                         orderby client.ClientId
                         select client;
           ViewData["clientlist"] = new SelectList(clients.ToList(),
"ClientId", "FirstName");
           return View();
My view has this code block:
       <tr>
           <td>Client</td>
           <td><%
                   var clients = ViewData["clientlist"] as
IEnumerable<SelectListItem>;
                   Html.DropDownList("clients", clients);
                   %></td>

Html extension methods return strings, they don't actually write to the
response for you.

Response.Write(Html.DropDownList("clients", clients));

Thanks!
 
Back
Top