//嗨,我正在构建一个 MVC4 项目,其中我有一个程序列表,每个程序都绑定到一个 Outlets 列表,一旦用户从我的下拉列表中选择一个程序,我就会尝试显示一个 Outlets 表,到目前为止我有一个jQuery function which fires whenever the selection changes and I am able to retrieve the program id for it .. great , but how do I make an ajax call to populate a table with the associated outlets to that program
我有一个负责绘制出口表的部分视图,我需要做的就是从我的 jQuery 函数中对我的控制器中的函数进行 ajax 调用并传递程序 ID,在这种情况下是var $input = $(this).find('option:selected').val();
控制器
public ActionResult AddOutletFromExisting()
{
int selectedValue = 0;
ViewBag.Programs = new SelectList(new ProgramRepository().GetPrograms(), "ProgramID", "ProgramName", selectedValue);
return View();
}
[HttpPost]
public ActionResult AddOutletFromExisting(FormCollection collection, int selectedValue=0)
{
var outlets = new OutletRepository().GetStoresByProgram(selectedValue).ToPagedList(1, 10);
return PartialView("_Outlets", outlets);
}
看法
@Html.DropDownList("ProgramID", (SelectList)ViewBag.Programs, string.Empty, new { id="dropdown" })
jQuery
$("#dropdown").change(function () {
var $input = $(this).find('option:selected').val();
//call a function in my controller and pass $input to this function
});