在搜索文本框中添加下拉列表

时间:2014-12-18 21:02:55

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

我需要在文本框中添加下拉列表以搜索用户。即,我希望下拉列表位于文本框内以搜索用户。 这就是我现在拥有的。

@using (Html.BeginForm())
{    
    <p>        
      City: @Html.DropDownList("UserCity", "All")
      Find by name: @Html.TextBox("SearchString") @Html.CheckBox("IsActive") Active Users               
     <input type="submit" value="Search"/>
    </p>            
}

这里的问题是,城市正在文本框上方显示以进行搜索,但我希望它像亚马逊搜索功能一样。 感谢。

2 个答案:

答案 0 :(得分:0)

您正在寻找自动填充功能,而不是文本框中的下拉列表

这里有两个很好的教程可以帮助你完成这个

mvc tutorial 1

mvc autocomplete tutorial

答案 1 :(得分:0)

我想在搜索框中或旁边有一个下拉列表。 我正在寻找的解决方案就是这个

@Html.ActionLink("Create New", "Create")
@using (Html.BeginForm(null, null, FormMethod.Get))
{         

      <div>  
               <div style="float: left; width: 300px; text-align: left;">            
           @Html.Label("SearchString", "Find By Name")
           @Html.TextBox("SearchString")
           </div>
               <div style="width:300px; margin: 0.5em 0 0 0; overflow:auto;">
           @Html.Label("UserCity", "City")
           @Html.DropDownList("UserCity", "All")
                   </div>
           <div style="margin: 0.5em 0 0 0; overflow:auto";>
           @Html.CheckBox("IsActive") Active Users                       
           <input type="submit" value="Filter" />
                   </div>
           </div>           

}

相关问题