如何使用modal绑定下拉列表中的值 [英] how to bind value in dropdown using modal

查看:135
本文介绍了如何使用modal绑定下拉列表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这里我想使用modal从数据库下拉绑定。但是我使用


$ b $绑定值b viewdata。亲切地帮助如何使用模态从数据库绑定下拉菜单。







描述: - <控制器中的


hi to all,
Here i want to bind in drop-down from database using modal.But i bind the value using

viewdata. so kindly help how to bind drop-down from database using modals.



DESCRIPTION:-
in controller

List<SelectListItem> list = new List<SelectListItem>();
               list.Add(new SelectListItem { Text = "Select Country", Value = "Select Country" });//set default text for DropdownList
               var cat = (from c in db.Country select c).ToArray();//get data from database using linq
               for (int i = 0; i < cat.Length; i++)

               {

                   list.Add(new SelectListItem { Text = cat[i].Country_Name, Value = cat[i].Country_Cde.ToString() });

               }

               ViewData["ViewCountry"] = list;





在视图中: -

@ Html.DropDownList(Country_Cde,(IEnumerable< SelectListItem>)ViewData [ViewCountry],new {id =Country_Cde,@ class =form-control control-text})



请建议我如何使用模态从数据库的下拉列表中绑定值。



in view:-
@Html.DropDownList("Country_Cde", (IEnumerable<SelectListItem>)ViewData["ViewCountry"], new { id = "Country_Cde", @class = "form-control control-text" })

Kindly suggest me how to bind values in drop-down from database using modals.

推荐答案

我建​​议你浏览以下链接:

为ASP.NET MVC中的枚举创建DropDownList [ ^ ]

如何简单的Html.DropDownListFor MVC.NET [ ^ ]



     - Amy
I would recommend you to go through the links below:
Creating a DropDownList for Enums in ASP.NET MVC[^]
How to simple Html.DropDownListFor MVC.NET[^]

    --Amy


型号:

列表< SelectListItem> ListItem = new List< SelectListItem>();





ListItem =来自表格数据中的itm

选择新的SelectList

{

Value = itm.Value,

Text = itm.Name

})。ToList( );









ListItem.Add(new SelectListItem { Value =" true",Text =" Yes"});

ListItem.Add(new SelectListItem {Value =" false",Text =" No"});



@html.DropDownListFor(m => m.Item,ListItem,new {});
Model :
List<SelectListItem> ListItem = new List<SelectListItem>();


ListItem = from itm in tabledata
select new SelectList
{
Value = itm.Value,
Text = itm.Name
}).ToList();


OR

ListItem.Add(new SelectListItem { Value = "true", Text = "Yes" });
ListItem.Add(new SelectListItem { Value = "false", Text = "No" });

@html.DropDownListFor(m=>m.Item, ListItem,new{});


这篇关于如何使用modal绑定下拉列表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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