0
"競合者"コンボボックスの選択した値を "xref"テキストボックスに添付された自動完成に渡す必要があります。オートコンプリートは最後のものが選択されていても、firtsアイテムの値だけを渡します。それを修正するには?jQueryオートコンプリート - 選択コンボボックス値
コントロール:
@Html.DropDownList("Competitor", (IEnumerable<SelectListItem>)ViewBag.Competitors, htmlAttributes: new { @class = "form-control" })
@Html.TextBox("xref", null, new { @class = "control-label col-lg-4 col-md-4 col-xs-4" })
オートコンプリートスクリプト:
$('#xref').autocomplete({
source: '/Products/TagSearch?Competitor=' + $('#Competitor').val()
});
コントローラー:助けを
public ActionResult TagSearch(string term, int Competitor)
{
string[] tags = { };
var myList = new List<string>();
var xrefs = db.CrossReferences.Where(p => p.CompetitorId == Competitor).Where(p => p.Reference.StartsWith(term));
if (xrefs != null)
{
foreach (var item in xrefs)
{
myList.Add(item.Reference.ToString());
}
tags = myList.ToArray();
}
return this.Json(tags.Where(t => t.StartsWith(term)),
JsonRequestBehavior.AllowGet);
}
感謝。