0

I writing ASP.NET MVC web app.

I have webpage here is design of it

Webpage

Here is DropdownListFor

Also I have model , here is code:

 public class Companies
{
    [Key]
    public int CompanyID { get; set; }



    [Display (Name = "Компания")]
    public string CompanyName { get; set; }


}

I need to display CompanyName in DropDownList CompanyName 's is in table (over 10)

I try to do it like this

@Html.DropDownListFor(m => m.Company, 
                new SelectList(Enum.GetValues(typeof(Companie_s))), 
                "Select Company")

But this right when I have enum and static values. Like this

public class Companies
{
    [Key]
    public int CompanyID { get; set; }



    [Display (Name = "Компания")]
    public Companie_s CompanyName { get; set; }
    public enum Companie_s
    {
        Ciklum,
        Luxoft
    }

}

How I need to write code in my case?

Thank's for help.

  • What is Companie_s ? – jao Feb 20 '17 at 19:15
  • Edited my post@jao –  Feb 20 '17 at 19:20
  • Did you take a look here: http://stackoverflow.com/a/694361/106866 ? If that isn't working, please show us what it looks like now. – jao Feb 20 '17 at 19:23
  • It is not clear what your question is. You want to know how to load your DropdownListFor with data from your model? If so, I don't believe it changed from version 3: http://stackoverflow.com/q/7142961/215552 – Heretic Monkey Feb 20 '17 at 19:23
  • Okay, I will try @MikeMcCaughan –  Feb 20 '17 at 19:25
  • I have one question. In this post he has `public IEnumerable ContribTypeOptions = new List { new Contrib {ContribId = 0, Value = "Payroll Deduction"}, new Contrib {ContribId = 1, Value = "Bill Me"} };` I wrote my code like this `public IEnumerable CompaniesOption = new List { };` But what I need to write inside list to get data with all companies in table? @MikeMcCaughan –  Feb 20 '17 at 19:41
  • Again, your question is confusing, and you didn't answer the question in my last comment. Are you hard-coding the list of companies in an Enum, or are you retrieving them from somewhere else? – Heretic Monkey Feb 20 '17 at 19:46
  • I try to hardcode and it works. I don't understood how to retrieve it from table, and because of it I post this question.@MikeMcCaughan –  Feb 20 '17 at 19:50
  • Seems I found answer here [answer](http://stackoverflow.com/questions/17108572/generate-dropdownlist-from-a-table-in-database) –  Feb 20 '17 at 19:59

0 Answers0