0

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 Answers 2

3

you want:

Update: fixed a bug

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

where "b" is the default selected value

Sign up to request clarification or add additional context in comments.

Comments

0

This works:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.