MVC如何获得部分改变DropDown

时间:2018-04-03 09:51:01

标签: c# asp.net-mvc forms post dropdown

有我的JobCenter.cshtml。我喜欢根据DropDown-List

更改输出
@{
   ViewBag.Title = "JobCenter";
   Layout = "~/Views/Shared/_Layout.cshtml";

   List<SelectListItem> systemItems = new List<SelectListItem>();
   systemItems.Add(new SelectListItem
   {
      Text = "Prod",
      Value = "prod"
   });
   systemItems.Add(new SelectListItem
   {
      Text = "Test",
      Value = "test",
   });
}

@using (Html.BeginForm("JobCenter", "Tool", FormMethod.Post))
{
   @Html.DropDownList("System", new SelectList(systemItems, "Value", "Text"), 
   new { onchange = "this.form.submit();" })
}

//Change & Reload this line on Change DropDown
@Html.Action("RunningJobs", "Tool", new { system = "prod" })

并且有我的控制器:

public ActionResult JobCenter()
{
    return View();
}

[HttpPost]
public ActionResult JobCenter(string system)
{
    ViewBag.sys = system;
    return View();
}

//[HttpPost]
public PartialViewResult RunningJobs(string system)
{
    DataTable result = null;
    switch(system)
    {
        case "prod":
            result = ProdRunnings;
            break;
        case "test":
            result = TestRunnings;
            break;
        case "qs":
            result = QSRunnings;
            break;
    }
    return PartialView(result);
}

我的目标是,如果我在DropDownBox中选择一个系统,相应地重新加载带有POST的PartialView(Post is system = prod / system = test)

感谢

0 个答案:

没有答案