2010-08-26 94 views
0

我想创建一个列表框中: http://blog.wekeroad.com/blog/aspnet-mvc-preview-using-the-mvc-ui-helpers/C#ASP.NET MVC 2:HTML.ListBox不起作用

的Html.ListBox不起作用:

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

我得到以下错误:

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

回答

3

你想:

更新:修正了一个错误

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

其中 “B” 是默认选择的值

+0

感谢您的回复,它的工作:d – mweber 2010-08-26 09:44:32

0

这工作:

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