views:

46

answers:

2

Hi,

I want to create a listBox: http://blog.wekeroad.com/blog/aspnet-mvc-preview-using-the-mvc-ui-helpers/

The Html.ListBox doesn't work:

<div class="editor-field">
    <%
        string[] movies = new string [] { "a", "b", "c" };
    %>
    <%: Html.ListBox("lala", movies, new string[] { "b" })%>
</div>

I get the following errors:

Error 1 'System.Web.Mvc.HtmlHelper<Transponder.Models.EditUserModel>' does not contain a definition for 'ListBox' and the best extension method overload 'System.Web.Mvc.Html.SelectExtensions.ListBox(System.Web.Mvc.HtmlHelper, string, System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>, System.Collections.Generic.IDictionary<string,object>)' has some invalid arguments 
Error 2 Argument 3: cannot convert from 'string[]' to 'System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>'
Error 3 Argument 4: cannot convert from 'string[]' to 'System.Collections.Generic.IDictionary<string,object>'
+2  A: 

you want:

Update: fixed a bug

<%: Html.ListBox("lala", new SelectList(movies, "b"))%>

where "b" is the default selected value

Andrew Bullock
thanks for your reply, it worked :D
mweber
A: 

This works:

<%: Html.ListBox("lala", new SelectList(new string[] { "a", "b", "c" }), new SelectList(new string[] { "b" }))%>

Jimmy