0

I'm trying to do the same as this ASP.NET MVC Using two inputs with Html.BeginForm question describes but with enough difference that I don't really know hwo to apply it on my project:

I have a view that has 3 dropdownlists(profilelist, connected salarylist & not connected salarylist)

Looks like this:

  <div class="row bgwhite">
           @using (Html.BeginForm("GetConnectedSalaries", "KumaAdmin", FormMethod.Get, new { Id = "ProfileListForm" }))
            {
              <div class="four columns list list1">
                  @Html.DropDownList("Profiles", (SelectList) ViewBag.Profiles, "--Välj profilgrupp--",
                  new 
                  {
                    //onchange = "$('#ProfileListForm')[0].submit();"
                    // Submits everytime a new element in the list is chosen
                    onchange = "document.getElementById('ProfileListForm').submit();"
                  })
              </div>
            }
            @using (Html.BeginForm("Index", "KumaAdmin", FormMethod.Get, new { Id = "SalaryListForm" }))
            {
                <div class="four columns list list2" style="margin-top:-19px;">
                    @Html.DropDownList("Salaries", (SelectList) ViewBag.Salaries, "--Kopplade LöneGrupper--") 
                </div>
            }

            @using (Html.BeginForm("GetNOTConnectedSalaries", "KumaAdmin", FormMethod.Get, new { Id = "NotConSalaryListForm" }))
            {
                <div class="four columns list list2" style="margin-top:-19px;">
                    @Html.DropDownList("Salaries", (SelectList)ViewBag.NotConSalaries, "--Ej Kopplade LöneGrupper--") 
                    <input style="float: left;" type="submit" value="Knyt" />
                </div>
            }
         </div>

as you can see above when i change an element i the profile list i have script code that submits the form and calls the following actionresult that populates my "connected salarylist".

  [HttpGet]
    public ActionResult GetConnectedSalaries(int Profiles = -1)
    {
        Model.SalaryGroups = AdminManager.GetConnectedSalaries(Profiles);
        ViewBag.Salaries = new SelectList(Model.SalaryGroups, "Id", "SalaryName", "Description");

        return (Index());
    } 

What I wan't to do:

When I chose a element in the profilelist i would like to call 2 actionresults, the one that i have shown above AND a second one that will populare my third list that will contain "not connected salaries". Second Actionresult:

 public ActionResult GetNOTConnectedSalaries(int Profiles = -1)
    {
        Model.SalaryGroups = AdminManager.GetNOTConnectedSalaries(Profiles);
        ViewBag.NotConSalaries = new SelectList(Model.NotConSalaryGroups, "Id", "SalaryName", "Description");

        return (Index());
    }

I don't want to do this with AJAX/JSON, strictly MVC. I read the question that i linked above but did not know how to apply it to my project or if it is even possible to do the same.

If more info is needed ask and i will do my best to provide it.

Thank you!

1
  • 1
    why not put logic of both the action in in a single action, as technically only a single action is taking place at client side though you want to return two results. Commented Mar 1, 2013 at 10:59

1 Answer 1

0

I was so sure that the best way to do this was to have two actionresults that i was totaly blinded to the soloution that i could call both my db methods from the same actionresult and populate both of the lists.

Simple soloution:

  [HttpGet]
    public ActionResult GetSalaries(int Profiles = -1)
    {
        Model.SalaryGroups = AdminManager.GetConnectedSalaries(Profiles);
        ViewBag.Salaries = new SelectList(Model.SalaryGroups, "Id", "SalaryName", "Description");
        Model.NotConSalaryGroups = AdminManager.GetNOTConnectedSalaries(Profiles);
        ViewBag.NotConSalaries = new SelectList(Model.NotConSalaryGroups, "Id", "SalaryName", "Description");

        return (Index());
    }

Sorry if I wasted your time:( but hopefully this will help others that attempt the same.

However if there is a way to do this in two actionresults then I will leave the question as open, would be interesting to see how it is done.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.