我如何创建ASP.NET MVC单选择模式一个ListBox? [英] How do I create a ListBox in ASP.NET MVC with single selection mode?

查看:139
本文介绍了我如何创建ASP.NET MVC单选择模式一个ListBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何创建ASP.NET MVC单选择模式一个ListBox?

How do I create a ListBox in ASP.NET MVC with single selection mode?

推荐答案

我假设你正在寻找一个选择框在视觉上像列表框,以显示多行的意思,但功能类似的DropDownList(允许只有一个选择) 。

I am assuming you are looking for a select box visually like the ListBox, meaning with multiple rows displayed, but functionally like the DropDownList (allowing for only one selection).

看起来没有使用列表框拉这一关一个特别简单的方法。我建议使用Html.DropdownList,与此类似:

It looks like there is not a particularly easy way to pull this off using ListBox. I'd suggest using Html.DropdownList, similar to this:

<%= Html.DropDownList("list1", 
    new Dictionary<string, object> {{"size", "5"}} ) %>

size属性将会给选择框列表框的外观。此外,您还需要将ViewData的项目从MultiSelectList改变的SelectList。

The size attribute will give the select box the look of a ListBox. Also, you will need to change your ViewData item from MultiSelectList to SelectList.

这篇关于我如何创建ASP.NET MVC单选择模式一个ListBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆