我有一個Dropdownlist連接到我的模型。加載頁面時,模型爲空,但在頁面上有一個用於更新模型的按鈕。我的問題是我的下拉列表不會更新。MVC更新使用jquery的下拉列表
標記:
@Html.DropDownList("ddlRaces", new SelectList(ViewBag.Races, "RaceId", "Name"))
<input type="button" id="btnChangeRace" class="btnGo" value=" " />
@Html.DropDownListFor(m => m.Timers, new SelectList(Model.Timers, "TimerId", "StartTime"), "Velg timer:")
腳本:
btnChangeRace.click(function() {
url = "/TimeMerger/GetTimers/?raceId=" + ddlRaces.val();
$.get(url);
});
代碼隱藏:
[HttpGet]
public ActionResult GetTimers(int raceId)
{
var timeMergeModel = new TimeMergerModel();
timeMergeModel.Timers = TimerModel.GetTimers(raceId);
return View(timeMergeModel);
}
向我們展示btnChangeRace和ddlRaces的聲明。 – 2011-03-04 12:10:48