dropdwonlist没有显示选定的值 [英] dropdwonlist not showing selected value

查看:174
本文介绍了dropdwonlist没有显示选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个包含列的html表。我在下面的列中添加了dropdownlistfor



@ Html.DropDownListFor(model => item.CategoryID,(IEnumerable< SelectListItem>)ViewData [categories], new {@id =category,DataValueField = item.CategoryID,DataTextField = item.CategoryName,SelectedValue = item.CategoryName})



但是从中检索数据时表并绑定到此表,此下拉列表未显示正确的值



任何人都可以帮助我..



谢谢

Kunjammu

Hi,

i have a html table having a column. i added dropdownlistfor in this column like below

@Html.DropDownListFor(model => item.CategoryID, (IEnumerable<SelectListItem>)ViewData["categories"], new { @id = "category", DataValueField = item.CategoryID, DataTextField = item.CategoryName, SelectedValue = item.CategoryName })

but when retrieving data from the table and bind to this table, this dropdown list not showing the correct value

can anybody help me..

thanks
Kunjammu

推荐答案

试试这个。在我的情况下它工作正常。

Try this. In my case it is working fine.
@Html.DropDownList("SelectedEmployee",   new SelectList((System.Collections.IEnumerable)ViewData["categories"], "CategoryId", "CategoryName"))





这里CategoryId和CategoryName是您的类别模型的属性。



Here CategoryId and CategoryName is the property of your Category model.


这篇关于dropdwonlist没有显示选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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