0

I'm trying to fill a DropList.For when I select an item from another DropList.For. Here is my code so far:

@Html.LabelFor(m => m.Cliente, new { @class = "control-label col-md-2" })
                            @Html.DropDownListFor(model => model.SelectedCategoryId,
                                    new SelectList(Model.Cliente, "CategoryId", "CategoryName"), "- Please Select -")
                            @Html.ValidationMessageFor(x => x.Cliente, null, new { @class = "label label-danger" })

                            @Html.LabelFor(m => m.Tipo_servicio, new { @class = "control-label col-md-2" })
                            @Html.DropDownListFor(model => model.SelectedCategoryId,
                                    new SelectList(Model.Tipo_servicio, "CategoryId", "CategoryName"), "- Please Select -")
                            @Html.ValidationMessageFor(x => x.Tipo_servicio, null, new { @class = "label label-danger" })

So I have it in my view and filled it with EntityFramework

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Inphyy
  • 5
  • 3
  • Depending on the size of the dataset you're trying to fill I'd say just load the data for the second droplist and filter the values when the value for the first dropdown is changed. – Dortimer May 15 '19 at 15:49
  • I understand, would I be coming back with a ViewBag? – Inphyy May 15 '19 at 15:51
  • In your Controller.cs file, on the method that returns the ActionResult for the view you're working on pass a model, something like `return View(model);` and just populate that model with all the data you need. – Dortimer May 15 '19 at 15:54
  • that will not cause me to refresh my sight and charge everything again? – Inphyy May 15 '19 at 16:06
  • I mean that you pass the entire data when you initially load the view. – Dortimer May 15 '19 at 16:11

1 Answers1

0

You can user "onChange" event, you can check below links.

  1. Using same method for multiple Dropdown: same method for multiple ddl

  2. different methods for different Dropdown: enter link description here

Thanks