mvc按下拉列表选择文本

时间:2014-05-22 02:43:17

标签: asp.net-mvc filter

我有以下过滤器

@using (Html.BeginForm("Index", "reqForm", FormMethod.Get))
        {
            <p>
                <b>Filter by:</b><br />
                <b>Start Date</b> @Html.TextBox("searchByDateS",ViewBag.DateSFilter as string)
                <b>End Date</b> @Html.TextBox("searchByDateE",ViewBag.DateEFilter as string)
                <b>Leave Type</b> @Html.DropDownList("searchByLvType", "All Typies")
                <input type="submit" value="search" />
            </p>
        }

控制器如下所示:

public ActionResult Index(string sortOrder, string currentFilter, string searchByDateS, string searchByDateE, string searchByLvType, int? page)
        {
            if (searchByDateS != null)
                page = 1;
            else
                searchByDateS = currentFilter;
...
 ViewData["searchByLvType"] = new SelectList(lr.GetLvType(), "id", "LvType");
...

选择参数searchByLvType。下拉列表中的值为searchLyType,如何将selected.text传递给参数?

1 个答案:

答案 0 :(得分:0)

使用输入类型隐藏

<input type="hidden" id="searchByLvTypeText" name="searchByLvTypeText"/>

当隐藏输入的下拉列值更改值

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="txt/javascript">
$(document).ready(function(){
    $("#searchByLvType").change(function()
     {
         $("#searchByLvTypeText").val($("#searchByLvType option:selected").text());
     });
});
</script>

然后在您的控制器中

public ActionResult Index(string sortOrder, string currentFilter, string searchByDateS, string searchByDateE, string searchByLvType, int? page,
string searchByLvTypeText)//drop down Text  
    {
}