Im new to ASP.Net MVC。私は約2時間を探していて、それを得ることができないようです。 データベースの製品のドロップダウンリストがあります。私が欲しいのは、テキストボックスの説明です。は、ドロップダウンリストの選択項目によってリアルタイムで表示されます。ここでドロップダウンリストで選択した値に応じてテキストボックスを入力しようとしています
は私がこれまで持っているものです。
はここ
public ActionResult Index()
{
IEnumerable<SelectListItem> items = db.Products.Select(i => new SelectListItem
{
Value = i.ProductName,
Text = i.ProductName
}
);
ViewBag.ProductItems = items;
return View();
}
マイドロップダウンリスト
@using (Ajax.BeginForm("GetDescriptionByProductName", "PurchaseOrder", new AjaxOptions{ InsertionMode = InsertionMode.Replace,UpdateTargetId = "description"}))
{
@Html.DropDownList("ProductItems", (SelectList)ViewBag.Values, new { onchange = "this.form.submit();" })
}
私のドロップダウンリストを読み込む私のコントローラで私のActionResultです
[HttpPost]
public ActionResult GetDescriptionByProductName(string ProductItems)
{
var data = db.Products.Where(x => x.Description.Contains(ProductItems));
return RedirectToAction("Index");
}
UPDATE:このすべては、RIGHT NOW BACK INDEXページにMEを指示され、BLANK
でのjQueryを使用していました。 – MrClan
今何をしようとしているのは、選択されたアイテムの値を取得し、コントローラに投げて、製品名の一致を検索し、その製品の説明を取得することです。 –
同じページに留まるためにajaxを使ってこれをしたいですか? –