@ html.dropdown在使用所选插件时不显示数据 [英] @html.dropdown not showing data when using chosen plugin

查看:138
本文介绍了@ html.dropdown在使用所选插件时不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制器:

 IList< SelectListItem> lstRelatedDocType =( from  o  in  db.OrderTypeJDEs 
select new SelectListItem(){Text = o.OrderTypeJDEID + - + o.OrderDescription,Value = o.OrderTypeJDEID,Selected = false })。ToList< SelectListItem>();

lstRelatedDocType.Where(w = > w.Value == RelatedDocType)。ToList()。ForEach(i = > i.Selected = true );

ViewBag.RelatedDocType = lstRelatedDocType;



现在我在viewbag中获取了数据。我希望它使用带有下拉列表的选定插件在视图上呈现并具有搜索功能。



查看:

 @ Html.DropDownList(RelatedDocType,ViewBag.RelatedDocType为SelectList,新{@class =RelatedDocType})



我的javascript:

 $( 。RelatedDocType)。selected( )



这里显示下拉列表,只显示第一条记录,其余部分未显示。请帮助我。







添加标签。

[/编辑]

解决方案

.RelatedDocType)。selected()



这里显示下拉列表并仅显示第一条记录,其余部分未显示.Plea请帮我。







已添加标签。

[/ Edit]


你应该改变你的剃刀代码:

 @ Html.DropDownList( RelatedDocType,(List< SelectListItem>)ViewBag.RelatedDocType,new {@class =RelatedDocType})


看到您正在过滤列表类型

 lstRelatedDocType.Where(w => w.Value == RelatedDocType)。ToList()。ForEach(i => i.Selected = true); 



这里看到列出多个项目的列表或不是吗?

 ViewBag.RelatedDocType = lstRelatedDocType; 



检查有多少项目被发送到viewbag 根据它是否加载到下拉列表?



和默认值选择

要拥有选择的文档,当从lstRelatedDocType加载文档时,使用以下SelectList类的重载构造函数。请注意,我们为selectedValue参数传递值 1

 ViewBag.RelatedDocType = new SelectList(lstRelatedDocType,Id,Name ,1);; 


controller:

IList<SelectListItem> lstRelatedDocType = (from o in db.OrderTypeJDEs
                                         select new SelectListItem() { Text = o.OrderTypeJDEID + "-" + o.OrderDescription, Value = o.OrderTypeJDEID, Selected = false }).ToList<SelectListItem>();

 lstRelatedDocType.Where(w => w.Value == RelatedDocType).ToList().ForEach(i => i.Selected = true);
 
 ViewBag.RelatedDocType = lstRelatedDocType;


Now I got my data in viewbag. I want it to render on view using chosen plugin with dropdown and having search functionality in it.

View:

@Html.DropDownList("RelatedDocType", ViewBag.RelatedDocType as SelectList, new { @class = "RelatedDocType" })


my javascript:

$(".RelatedDocType").chosen()


Here it is displaying dropdown and showing only first record and the rest were not shown.Please help me.


[Edit member="Tadit"]
Added pre tags.
[/Edit]

解决方案

(".RelatedDocType").chosen()


Here it is displaying dropdown and showing only first record and the rest were not shown.Please help me.


[Edit member="Tadit"]
Added pre tags.
[/Edit]


You should change your razor code like this:

@Html.DropDownList("RelatedDocType", (List<SelectListItem>)ViewBag.RelatedDocType, new { @class = "RelatedDocType" })


see you are filtering your list type

lstRelatedDocType.Where(w => w.Value == RelatedDocType).ToList().ForEach(i => i.Selected = true);


See here the list taking more than one items or not?

ViewBag.RelatedDocType = lstRelatedDocType;


check how many items are insrted to viewbag as per it's loading to dropdownlist or not?

AND for default value selection
To have the document selected, when the documents are loaded from lstRelatedDocType, use the following overloaded constructor of SelectList class. Notice that we are passing a value of 1 for selectedValue parameter.

ViewBag.RelatedDocType = new SelectList(lstRelatedDocType, "Id", "Name", "1″);; 


这篇关于@ html.dropdown在使用所选插件时不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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