0

I am new to MVC and have been told not to use SelectListItem in the View as its untidy. I was advised to put it in the Model and then pass to the view.

I have no idea whether my code in the Model is correct. Any assistance would be highly appreciated. Code is here:

public class ZipCodeModel
    {
        public string ZipCode { get; set; }


        public static readonly
            IEnumerable<SelectListItem> items;

        static ZipCodeModel()
        {
            items = new List<SelectListItem>
            {
                new SelectListItem {Text = "A"},
                new SelectListItem {Text = "B"},
                new SelectListItem {Text = "C"},
                new SelectListItem {Text = "D"}
            };
        }
    }

Thanks in advance :)

4

1 回答 1

0

尝试这个

@Html.DropDownListFor(m => m.ZipCodeModel, 
      new SelectList(m.audioThemes, "Value", "Text"), new { @class = "class" })
于 2013-07-25T11:04:51.780 回答