I am developing an ASP .Net MVC 3 application using C# and SQL Server 2005.
I am using also Entity Framework and Code First Method.
I have a view 'Application' which contain a DropDownList and a Table.
The items of DropDownList are being loaded from the base (Table=Genre) in form of a list.
According to the selected item in the DropDownList, I want didplay some values (list) in the base in form of CheckBox in the table.
I tried CheckBoxFor but it's not working.
This is the View :
<div>
<%:Html.Label("Type :")%><%: Html.DropDownListFor(model => model.SelectedGenre, Model.GenreItems)%>
</div>
<table border = "transparent">
<tr>
<th>
</th>
</tr>
<% foreach (var item in Model.FaItems) { %>
<tr>
<td>
<%: Html:CheckBoxFor (modelItem => item.Nom_Famille) %>
</td>
</tr>
<% } %>
</table>
and this is the Controller :
[HttpGet]
public ActionResult Application(Genre genre)
{
var vv = new FlowViewModel();
vv.GenreItems = new SelectList(db.Genres.ToList(), "ID_G", "ID_G");
if (vv.SelectedGenre == "Famille")
{
vv.FaItems = db.Familles.ToList();
}
else if (vv.SelectedGenre == "Sous Famille")
{
vv.SFItems = db.Sous_Familles.ToList();
}
return View(vv);
}
and this is the model :
public class FlowViewModel
{
[Key]
public string IDv { get; set; }
public List<Famille> FaItems { get; set; }
public List<Sous_Famille> SFItems { get; set; }
[NotMapped]
public SelectList GenreItems { get; set; }
public string SelectedGenre { get; set; }
public FlowViewModel()
{
FaItems = new List<Famille>();
SFItems = new List<Sous_Famille>();
}
}
NOTE :
I want choose some values of the list (check them) and record that in the base, if you have any another suggestion except checkbox, that's will be very useful. Thanks.