0

there is my JobCenter.cshtml. I like to change an Output in dependency of a 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" })

and there is my Controller:

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);
}

my goal is it if I select a system in the DropDownBox, which is reloaded accordingly a PartialView with a POST (the Post is system=prod / system=test)

thanks

beari7
  • 105
  • 2
  • 15
  • I'd like to Get like this: https://css-tricks.com/examples/DynamicDropdown/ but the second Part should be a PartialView, and the Content of this view ist based on a Post parameter <- and based on MVC – beari7 Apr 03 '18 at 10:13
  • Use javascript Ajax.BeginForm (instead of Html.BeginForm). https://stackoverflow.com/questions/17095443/how-to-use-simple-ajax-beginform-in-asp-net-mvc-4 – EzLo Apr 03 '18 at 12:58

0 Answers0