asp.net mvc - MVC - DropDownList from database -


i have error when want save selected country.

here error:

in french:

     l'élément viewdata avec la clé « country » est de type       « system.string » mais doit être de type « ienumerable<selectlistitem> ». 

in english :

         viewdata key "country" « system.string » must « ienumerable<selectlistitem> ». 

here code :

in controller:

    public actionresult getmeth()     {         var countries = _bll.countrycodes.findall();         viewdata["listitems"] = c in countries                                       select new selectlistitem()                                       {                                           text = c.namefr,                                           value = c.code                                       };         return view();     }      public actionresult postmeth(mymodel model)     {            ...            ...            country = model.country;            ...            ...     } 

in viewmodel:

    [display(name = "country")]     public string country { get; set; } 

in view:

    @html.dropdownlistfor(m => m.country, (ienumerable<selectlistitem>) viewdata["listitems"]) 

can me please, tried lot of solution can't resolve it

thank much!

edit:

when put

    [display(name = "pays")]     public ienumerable<selectlistitem> country { get; set; } 

i have error :

the element viewdata key « country » « system.collections.generic.list`1[[system.web.webpages.html.selectlistitem, system.web.webpages, version=2.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35]] » must « ienumerable ».


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -