このページでは、ドロップダウン リストから項目を選択し、次のように、選択したパラメーターをコントローラーの新しいアクションに ajax 呼び出しで渡します。
function select(e) {
var unit = $("#unitList").data("kendoDropDownList").value();
var url = '@Url.Content("~/Reports/UnitRunReport/")';
$.ajax({
url: url,
data: { selectedUnit: unit },
type: 'GET',
dataType: 'json',
success: function (data) {
//
},
error: function () {
//
}
});
}
これが私のコントローラーです:
public class ReportsController : BaseController
{
public ReportsViewModel Model { get; set; }
//
// GET: /Reports/
public ActionResult Index()
{
Model = new ReportsViewModel
{
Units = UnitClient.GetListOfUnits(true, "")
};
return View(Model);
}
[HttpGet]
public ActionResult UnitRunReport(string selectedUnit)
{
var unit = Convert.ToInt32(selectedUnit);
Model = new ReportsViewModel
{
UnitRuns = RunClient.GetRunListForUnit(unit)
};
return View(Model);
}
}
2 つのアクション (Index と UnitRunReport) のビューを分離する必要があります。デバッグ時に、正しいパラメーターを UnitRunReport アクションに渡し、return View(Model)
ステートメントを移動します。インデックス ページから新しい UnitRunReport ビューにリダイレクトされない理由を誰か説明してもらえますか?