C# Can';是否将viewdata下拉列表的选定值获取到我的控制器操作?

C# Can';是否将viewdata下拉列表的选定值获取到我的控制器操作?,c#,.net,asp.net-mvc,C#,.net,Asp.net Mvc,我无法将DropDownList的选定值传送到我的控制器。字符串I search被传递给控制器,但下拉列表的选定值不被传递 控制器 public ActionResult Index() { 列表项=新列表(); 添加(新建SelectListItem{Text=“Movies”,Value=“0”,Selected=true}); 添加(新SelectListItem{Text=“Tv Seires”,Value=“1”}); 添加(新SelectListItem{Text=“Cast”,Va

我无法将
DropDownList
的选定值传送到我的控制器。字符串I search被传递给控制器,但下拉列表的选定值不被传递

控制器
public ActionResult Index()
{
列表项=新列表();
添加(新建SelectListItem{Text=“Movies”,Value=“0”,Selected=true});
添加(新SelectListItem{Text=“Tv Seires”,Value=“1”});
添加(新SelectListItem{Text=“Cast”,Value=“2”});
添加(新SelectListItem{Text=“All”,Value=“3”});
ViewData[“选项”]=项目;
返回视图();
}
看法

@Html.DropDownList(“选项”,ViewData[“选项”]作为SelectList,新的{@class=“btn btn辅助下拉开关”,@id=“search_dropdown”})
@TextBoxFor(m=>m.searchValue,new{htmlAttributes=new{@class=“form control”,@id=“search\u input”,placeholder=“search term…”})

考虑将其放入表单中:

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    @Html.DropDownList("Options",ViewData["Options"]as SelectList, new { @class = "btn btn-secondary dropdown-toggle", @id = "search_dropdown" })

    @Html.TextBoxFor(m => m.searchValue,new{htmlAttributes = new {@class = "form-control", @id="search_input",placeholder="Search term..."}})

    <input type="submit" value="&#x1f50d;" class="btn btn-secondary" id="search_button" />
}
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.DropDownList(“选项”,ViewData[“选项”]作为SelectList,新的{@class=“btn btn辅助下拉开关”,@id=“search_dropdown”})
@TextBoxFor(m=>m.searchValue,new{htmlAttributes=new{@class=“form control”,@id=“search\u input”,placeholder=“search term…”})
}

或。。。在模型中使用DtopDownListFor。谢谢您的回答,我后来找到了解决方案,我创建了一个字典并将其绑定到模型中的属性。您正在尝试在此处创建搜索,对吗?(将此添加到问题中)下拉列表由类别组成,在您提供的代码中-它按预期显示和填充下拉列表,但当您执行某些操作(如用户提交搜索)时,它不会传回控制器,对吗?hench这是一个控制视图状态考虑?正确@BrettCaswell。谢谢你的编辑,但我找到了解决办法。
<div class="input-group">
    <div class="input-group-btn search-panel">
        @Html.DropDownList("Options",ViewData["Options"]as SelectList, new { @class = "btn btn-secondary dropdown-toggle", @id = "search_dropdown" })
    </div>
    @Html.TextBoxFor(m => m.searchValue,new{htmlAttributes = new {@class = "form-control", @id="search_input",placeholder="Search term..."}})
    <span class="input-group-btn">
        <input type="submit" value="&#x1f50d;" class="btn btn-secondary" id="search_button" />
    </span>
</div>
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    @Html.DropDownList("Options",ViewData["Options"]as SelectList, new { @class = "btn btn-secondary dropdown-toggle", @id = "search_dropdown" })

    @Html.TextBoxFor(m => m.searchValue,new{htmlAttributes = new {@class = "form-control", @id="search_input",placeholder="Search term..."}})

    <input type="submit" value="&#x1f50d;" class="btn btn-secondary" id="search_button" />
}