我怎样才能得到这个ASP.NET MVC的SelectList工作? [英] How can I get this ASP.NET MVC SelectList to work?

查看:158
本文介绍了我怎样才能得到这个ASP.NET MVC的SelectList工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的控制器创建一个选择列表,在视图中显示。

I create a selectList in my controller, to display in the view.

我想即时创建它,八九不离十的事..这样...

I'm trying to create it on the fly, sorta thing .. like this...

myViewData.PageOptionsDropDown = 
   new SelectList(new [] {"10", "15", "25", "50", "100", "1000"}, "15");

它编译,但输出是坏的......

It compiles, but the output is bad...

<select id="PageOptionsDropDown" name="PageOptionsDropDown">
    <option>10</option>
    <option>15</option>
    <option>25</option>
    <option>50</option>
    <option>100</option>
    <option>1000</option>
</select>

注意,没有项目是如何选定的?

我怎样才能解决这个问题?

How can I fix this??

推荐答案

这是我要做的事。

IList<Customer> customers = repository.GetAll<Customer>();
IEnumerable<SelectListItem> selectList = 
    from c in customers
    select new SelectListItem
    {
    	Selected = (c.CustomerID == invoice.CustomerID),
    	Text = c.Name,
    	Value = c.CustomerID.ToString()
    };

在第二眼我不知道我知道你是什么......之后

At second glance I'm not sure I know what you are after...

这篇关于我怎样才能得到这个ASP.NET MVC的SelectList工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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