dropdownlist在mvc4中获取所选值的默认值 [英] dropdownlist getting default value insted of selected value in mvc4

查看:70
本文介绍了dropdownlist在mvc4中获取所选值的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从mvc4中的下拉菜单中获得正确的值。我的编辑视图代码是

i am unable to get correct value from drop down in mvc4. my edit view code is

@Html.DropDownList("IDCountry", (IEnumerable<SelectListItem>)ViewBag.IDCountry, 
    new { @class = "span6" })





如果我使用以下代码我能够获得正确的价值但我无法为下拉列表申请风格



if i use below code am able to get correct value but am unable to apply style for dropdownlist

@Html.DropDownList("IDCountry",String.empty)





请解决我的问题。



please solve my problem.

推荐答案

如果你看一下重载 [ ^ ],你会发现这两个不一样。如果你也想指定默认空值,我建议这个重载 [ ^ ]。



If you look at the overloads[^], you will see that these two are not the same. If you want to specify default empty value also, I suggest this overload[^].

@Html.DropDownList("IDCountry", (IEnumerable<SelectListItem>)ViewBag.IDCountry, String.empty, new { @class = "span6" })


@Html.DropDownList("IDCountry", (IEnumerable<SelectListItem>)ViewBag.IDCountry,"String"
    new { @class = "span6" })


这篇关于dropdownlist在mvc4中获取所选值的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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