Ok i found a way, but I'm not sure whether it's the best approach.
a new Model class
public class Countries
{
public virtual string citizenship { get; set; }
}
in the controller, in my case in both get and post
TDAL tda = new TDAL();
//////////////////////
List<SelectListItem> list= new List<SelectListItem>();
list.Add(new SelectListItem { Text = "All", Value = "0" });
var cat = tda.getCountries().ToArray();
for (int i = 0; i < cat.Length; i++)
{
list.Add(new SelectListItem
{
Text = cat[i].citizenship,
Value = cat[i].citizenship.ToString(),
Selected = (cat[i].citizenship == "1")
});
}
ViewData["citizen"] = list;
////////////////////////////
return View();
DAL class
public IList<Countries> getCountries()
{
IList<Ter.Models.Countries> countries;
IQuery query;
using (ISession session = OpenSession())
{
try
{
query = session
.CreateQuery("select distinct citizenship AS citizenship from Ters")
.SetResultTransformer(Transformers.AliasToBean<Countries>());
}
catch (Exception c)
{
query = null;
}
countries = query.List<Countries>();
}
return countries;
}
and the view
@Html.DropDownList("citizenship", (IEnumerable<SelectListItem>)ViewData["citizen"], new { id = "citizenship" })