2010-08-26 7 views
0

Je veux créer une zone de liste: http://blog.wekeroad.com/blog/aspnet-mvc-preview-using-the-mvc-ui-helpers/C# ASP.NET MVC 2: HTML.ListBox ne fonctionne pas

Le Html.ListBox ne fonctionne pas:

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

Je reçois le texte suivant erreurs:

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

Répondre

3

vous voulez:

Mise à jour: Correction d'un bug

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

où "b" est la valeur par défaut sélectionnée

+0

merci pour votre réponse, il a travaillé: D – mweber

0

Cela fonctionne:

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