vendredi 29 janvier 2016

filter DropDownList with viewbag in mvc3

I have two tables: Persons and Activities. First I create the persons. When I want to create an activity for that person, I have a DropDownList from which I choose the persons. What I want is to filter the DropDownList so that if a person is already linked to an activity, I don't want her to appear in the DropDownList. In the Activities table I have a column Called STATUS and I want to filter by this column. Here is what I have in Controller:

ViewBag.SelectListPers = new SelectList
(
from c in p.ToList()
where dbContext.Activities.Any(k=>k.STATUS=='0')
select new 
{
ID_PERS=c.ID_PERS,
FullName=c.FirstName+""+c.Surname
},"ID_PERS", "FulName"
);

And in View:

<%: Html.DropDownListFor(model=>model.ID_PERS,ViewBag.SelectListPers as SelectList, "Select a person")%>

This is not working. Could you help me?

Aucun commentaire:

Enregistrer un commentaire