ASP.Net MVC RC DropDownList

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>
 
A

Anthony Jones

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));
 
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>

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

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

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top