Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I filter a list with a dropdown list
    text
    copied!<p>I am new to MVC, and I want on my view two things:</p> <p>1 - A list of data's (3 columns) 2 - A dropdown list that I can filter the list (filled with data from the first column) </p> <p>in my controller I have the following function: </p> <pre><code>public ViewResult ListUrl() { var ws = new Service1(); localhost.Service1 s1 = new Service1(); // data from web services localhost.UrlInfo[] ui = s1.GetUrlInfo(); for (int i = 0; i &lt; ui.Length; i++) { var UrlItem = new UrlItem(); UrlItem.Id = Convert.ToInt32(ui[i].Id); UrlItem.urlll = ui[i].url; UrlItem.toontijd = ui[i].ToonTijd; UrlItem.positie = Convert.ToInt32(ui[i].positie); Models.ListUrl.UrlList.Add(UrlItem); } var urlname = from url in s1.GetUrlInfo() select url ; ViewData["url"] = new SelectList(urlname, "Id", "url"); return View(); } </code></pre> <p>In the view :</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function () { // How can I filter the list (see &lt;table&gt; tag) when I change index of dropdown list??? }); &lt;/script&gt; @Html.DropDownList("SelectedItem", (SelectList)ViewData["url"], "----- all ------", new { id = "0", text = "----- all ------" }) &lt;table&gt; &lt;tr&gt; &lt;th&gt; Url &lt;/th&gt; &lt;th&gt; Toontijd &lt;/th&gt; &lt;th&gt; Positie &lt;/th&gt; &lt;/tr&gt; @foreach (var item in ListUrl.UrlList) { &lt;tr&gt; &lt;td&gt; @item.urlll.ToString() &lt;/td&gt; &lt;td&gt; @item.toontijd.ToString() &lt;/td&gt; &lt;td&gt; &lt;/td&gt; &lt;td&gt; @item.positie.ToString() &lt;/td&gt; &lt;/tr&gt; } </code></pre> <p></p> <p>How to get dropdownlist change event working? Thanks a lot.</p> <p>Hicham.</p>
 

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