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!
 
Joined
Nov 24, 2009
Messages
1
Reaction score
0
Did that work

cksanjose said:
On Feb 17, 6:53*am, "Anthony Jones" <[email protected]>
wrote:
> "cksanjose" <[email protected]> wrote in message
>
> news:fc58b8f0-dafe-44d6-aa56-b86bfbaf9070@i38g2000yqd.googlegroups.com...
>
>
>
> > 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));
>
> --
> Anthony Jones - MVP ASP/ASP.NET


Thanks!

So did you code changed from this:
<td><%
> > var clients = ViewData["clientlist"] as
> > IEnumerable<SelectListItem>;
> > Html.DropDownList("clients", clients);
> > %></td>
To:
<td><%
> > var clients = ViewData["clientlist"] as
> > IEnumerable<SelectListItem>;
Response.Write(Html.DropDownList("clients", clients));>
%></td>[/
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top