本文介绍了如何在ASP.NET MVC 4中获取DropDownList SelectItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on application using asp.net mvc 4. Here i have a dropdownlist which is showing some list of amount. My Model Named Search have a variable named Minimum of decimal type which i have shown in dropdownlist as

@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" })

此下拉列表位于表单标签下,提交后,该表单将执行以显示详细信息"为标题的操作,如下所示:

This dropdwonlist is under form tag whose on submit this form goes to action nemed "Display Details" which is as follows

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

但是在这里,我得到选择的值,但没有选择文本".我如何在这里获取所选文本.

But here i am getting selected value but not it selected Text. How i can get the selected text Here.

推荐答案

您有两个选择,

选项1 .将Value =文本放在下拉列表中

Option 1. put Value = Text in dropdown

选项2 .取一个名称为"MinimumValue"的隐藏字段,然后在表单字段中将选定的下拉文本提交到隐藏字段"MinimumValue"中,然后可以将值获取为Request.Form ["MinimumValue"]

Option 2. Take one Hidden field with some Name say "MinimumValue" and before submitting the form store selected dropdown text in hidden field "MinimumValue" then you can get the value as Request.Form["MinimumValue"]

让我知道您是否需要更多帮助

Let me know if you need more help

这篇关于如何在ASP.NET MVC 4中获取DropDownList SelectItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 16:03