using jQuery to control a drop down list
<select id="DropList">
@foreach (var item in Model.CategoryList)
{
<option value="@item.Id">
@item.Name
</option>
}
</select>
This list holds categories of pictures. There is a database holds pictures information and categoy information. When i choose a category from the list, i want to see all the pictures that 开发者_JS百科belong to the category. This is my list. I want the controller to give me pictures when i change the value in the list. I am using jQuery to take the id from the selected list element but how can i get the pictures.
This code works:
@foreach (var item in Model.CategoryList)
{
<a id="aa" href="@Url.Action("Index", "Home", new { id = @item.Id })">@item.Name</a>
<br />
}
<br />
<a href="@Url.Content("http://localhost:55197/Home/CategoryEkle")">Yeni Kategori Ekle</a>
I want to the same for the drop down list.
@Rory's comment on your post is a good one. But rather than putting it in the ViewModel (since controllers don't care about the way that views display things), I'd do this in the view:
@{
var cats = new List<SelectListItem>();
foreach (var item in Model.CategoryList)
cats.Add(new SelectListItem() { Text = item, Value = item.Id });
}
@Html.DropDownList("DropList", cats)
精彩评论