我正在尝试根据下拉选择的值填充自动完成文本框,但无法将选择的下拉值作为参数传递给自动完成 url.Action()
这是我正在使用的代码..
Dictionary<string, string> searchlist = new Dictionary<string, string>();
searchlist.Add("option1", "1");
searchlist.Add("option2", "2");
searchlist.Add("option3", "3");
searchlist.Add("option4", "4");
SelectList list = new SelectList(searchlist, "value", "key");
@Html.DropDownListFor(m => m.SearchType, list, new {@id="category", @class = "select" })
<script type="text/javascript">
$(document).ready(function () {
$("#category").change(function () {
var selectedVal = $("#category option:selected").text();
alert("You selected :" + selectedVal);
});
});
</script>
<input type="text" id="searchField" name="searchField" data-autocomplete-url="@Url.Action("Autocomplete", "Home", new { lang = Model.Language, cattype = selectedVal })" class="select" value="Search" onBlur="if(this.value == '') this.value = 'Search';" onFocus="if(this.value == 'Search') this.value = '';" />
<a href="#"><img src="@Url.Content("~/Content/images/magnifier.png")" alt="Search" title="Search" /></a>
请帮助我我哪里出错了。提前致谢。