Note that there are some explanatory texts on larger screens.

plurals
  1. POAsp.net MVC populate a list box with JQuery?
    primarykey
    data
    text
    <p>I have a list of Payees in a drop down box on my form. I would like to populate a different drop down, based on the selected item of the Payee drop down, without post backs and all that.</p> <p>So, I created a method in my controller that does the work:</p> <pre><code> private JsonResult GetCategories(int payeeId) { List&lt;CategoryDto&gt; cats = Services.CategoryServices.GetCategoriesByPayeeId(payeeId); List&lt;SelectListItem&gt; items = new List&lt;SelectListItem&gt;(); foreach(var cat in cats) { items.Add(new SelectListItem {Text = cat.Description, Value = cat.CategoryId.ToString()}); } return Json(items); } </code></pre> <p>Now, I am unsure what to add to my view to get this to work.</p> <p>At the moment, all I have is this:</p> <pre><code> &lt;% using (Html.BeginForm()) {%&gt; &lt;p&gt; &lt;%=Html.DropDownList("SelectedAccountId", Model.Accounts, "Select One..", null) %&gt; &lt;/p&gt; &lt;p&gt; &lt;%=Html.DropDownList("SelectedPayeeId", Model.Payees, "Select One...", null) %&gt; &lt;/p&gt; &lt;input type="submit" value="Save" /&gt; &lt;% }%&gt; </code></pre> <p>they populate fine... so when the user selects the SelectedPayeeId drop down, it should then populate a new (Yet to be created?) drop down which holds categories, based on the SelectedPayeeId.</p> <p>So, I think I need to create a JQuery function (Never done JQuery.. so not even sure where it goes) which monitors the Payee drop down for an onChange event? And then call the method I created above. Does this sound right, and if so, can you guide me in how to achieve this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload