我想使用MVC从数据库的下拉列表中添加数据.请帮帮我吗? [英] I want to add data in dropdown list from database using MVC.please help me out?

查看:98
本文介绍了我想使用MVC从数据库的下拉列表中添加数据.请帮帮我吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用MVC从数据库的下拉列表中添加数据.请帮帮我吗?
我现在在我的asp页面中添加了下拉列表,我想填充其中的数据来自数据库.

I want to add data in dropdown list from database using MVC.please help me out?
I have add dropdown in my asp page now i want to populate data in it coming from database.

推荐答案

您必须将SelectList实例传递给视图.您可以像这样将其添加到视图包(或视图模型)中:
You have to pass a SelectList instance to the view. You can either add it to the viewbag (or to the viewmodel) like this:
ViewBag.DropDown = new SelectList(IEnumerable of elements to be listed in the dropdown, "element field to be used as index", "element field to be used as display text")};



比您可以在自己的视图中使用它的方式:



Than you can use it in your view:

@Html.DropDownList("DropDown")



当然,请向MSDN咨询其他功能:
http://msdn.microsoft.com/en-us/library/system. web.mvc.selectlist.aspx [ ^ ]
http://msdn.microsoft .com/en-us/library/system.web.webpages.html.htmlhelper.dropdownlist(v = vs.99).aspx [



Of course consult MSDN for other features:
http://msdn.microsoft.com/en-us/library/system.web.mvc.selectlist.aspx[^]
http://msdn.microsoft.com/en-us/library/system.web.webpages.html.htmlhelper.dropdownlist(v=vs.99).aspx[^]


这篇关于我想使用MVC从数据库的下拉列表中添加数据.请帮帮我吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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