【问题标题】:How to get DropDownList SelectItem in asp.net mvc 4如何在 asp.net mvc 4 中获取 DropDownList SelectItem
【发布时间】:2015-08-21 19:23:07
【问题描述】:

我正在使用 asp.net mvc 4 开发应用程序。这里我有一个下拉列表,其中显示了一些金额列表。我的模型命名搜索有一个名为最小十进制类型的变量,我在下拉列表中显示为

@Html.DropDownList("Minimum", new List<SelectListItem>
                              { 
                            new SelectListItem { Text="Less Than 5000", Value="1"},
                            new SelectListItem { Text="5000", Value="2"},
                            new SelectListItem { Text="10,000", Value="3"},
                            new SelectListItem { Text="15,000", Value="4"},
                            new SelectListItem { Text="20,000", Value="5"},
                            new SelectListItem { Text="25,000", Value="6"},
                            new SelectListItem { Text="30,000", Value="7"},
                            new SelectListItem { Text="35,000", Value="8"},
                            new SelectListItem { Text="40,000", Value="9"},
                            new SelectListItem { Text="50,000", Value="10"},
                            new SelectListItem { Text="60,000", Value="11"},
                            new SelectListItem { Text="70,000", Value="12"},
                            new SelectListItem { Text="80,000", Value="13"},
                            new SelectListItem { Text="90,000", Value="14"},
                            new SelectListItem { Text="1,00,000", Value="15"},
                            new SelectListItem { Text="5,00,000", Value="16"},
                            new SelectListItem { Text="10,00,000", Value="17"}
                              }, new { @class = "selectpicker" })

此 dropdwonlist 位于表单标签下,提交此表单时将执行名为“显示详细信息”的操作,如下所示

public ActionResult DisplayDetails(Search objCust)
{
    objCust.Minimim = Convert.ToDecimal(Request.Form["Minimim"]);
}

但在这里我得到的是选定的值,但不是它选定的文本。我如何在此处获取所选文本。

【问题讨论】:

  • 将每个SelectListItemValue属性设置为与Text属性相同

标签: c# asp.net asp.net-mvc asp.net-mvc-4


【解决方案1】:

你有两个选择,

选项 1。将 Value = Text 放入下拉列表中

选项 2。取一个名称为“MinimumValue”的隐藏字段,然后在提交表单之前将选定的下拉文本存储在隐藏字段“MinimumValue”中,然后您可以将值作为 Request.Form["MinimumValue"]

如果您需要更多帮助,请告诉我

【讨论】:

  • 这是一个很好的解决方案。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-30
  • 1970-01-01
  • 2015-11-04
  • 1970-01-01
  • 2013-08-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多