动态下拉列表创建和在局部视图中添加模型数据 [英] dynamic dropdown list creation and adding model data in partial view

查看:84
本文介绍了动态下拉列表创建和在局部视图中添加模型数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

列表与LT; VentureLocation> _locationList = new List< VentureLocation>(); 



i从数据库添加数据到list.list有2个cloums id,现在位置。这些记录是在视图包中获取

ie,

 ViewBag.leftcontent = _locationList; 
返回PartialView(_locationList);



然后如何将此数据添加到dropdownlist id作为datavalue字段和位置作为datatext提交。

请回复我

解决方案

你可以这样写...



 ViewBag.leftcontent =新SelectedList(_locationList,  Id  location < yourdefaultlocationtoselect> ); < /   yourdefaultlocationtoselect  >  


List<VentureLocation> _locationList = new List<VentureLocation>();


i added data from database to list.list is having 2 cloums id,location now.these records is taken in view bag
i.e,

 ViewBag.leftcontent=_locationList;
return PartialView(_locationList);


then how to add this data to dropdownlist id as datavalue field and location as datatext filed.
please reply me

解决方案

you can write like this...

ViewBag.leftcontent= New SelectedList(_locationList,"Id","location","<yourdefaultlocationtoselect>");</yourdefaultlocationtoselect>


这篇关于动态下拉列表创建和在局部视图中添加模型数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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