我是 MVC 的新手,我想在我的观点上做两件事:
1 - 数据列表(3 列) 2 - 我可以过滤列表的下拉列表(填充第一列中的数据)
在我的控制器中,我具有以下功能:
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 < 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();
}
在视图中:
<script type="text/javascript">
$(document).ready(function () {
// How can I filter the list (see <table> tag) when I change index of dropdown list???
});
</script>
@Html.DropDownList("SelectedItem", (SelectList)ViewData["url"], "----- all ------", new { id = "0", text = "----- all ------" })
<table>
<tr>
<th>
Url
</th>
<th>
Toontijd
</th>
<th>
Positie
</th>
</tr>
@foreach (var item in ListUrl.UrlList)
{
<tr>
<td>
@item.urlll.ToString()
</td>
<td>
@item.toontijd.ToString()
</td>
<td>
</td>
<td>
@item.positie.ToString()
</td>
</tr>
}
如何使下拉列表更改事件起作用?非常感谢。
希查姆。