【发布时间】:2013-07-04 02:15:21
【问题描述】:
我是 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>
}
如何让下拉列表更改事件起作用? 非常感谢。
希查姆。
【问题讨论】:
-
我不是 MVC 专家,但我知道下拉列表有“autopostback”属性,尝试将其设置为“true”并绑定事件“yourdropdownlist_SelectedIndexChanged”,希望对您有所帮助
-
@losSebos: autopostback-and-MVC?!不知道的请不要推荐..
-
@Paritosh:我知道:stackoverflow.com/questions/730800/… 然后使用回发事件调用你的函数
标签: c# asp.net-mvc asp.net-mvc-4