0

I want to make a preset Dropdownlist in asp MVC for a simple email form. I found an example that works great but can't get spaces in the list. I want a space between "GeneralInformation" to "General Information" the example doesn't work for spaces. I'm using dropdownlistfor

I have

public enum feedbackDDL
{
    GeneralInformation,
    feedback,
    QuestionComments
}

I used example http://www.tutorialsteacher.com/mvc/htmlhelper-dropdownlist-dropdownlistfor

Here is my model

public class ContactModel
{

    [Required(ErrorMessage = " Required")]
    public feedbackDDL ContactDDL { get; set; }

}

public enum feedbackDDL
{
    GeneralInformation,
    feedback,
    QuestionComments
}

here Is my view

        @Html.Label("ContactDDL", "Feedback* ")@Html.ValidationMessage("ContactDDL")<br />

        @Html.DropDownListFor(m => m.ContactDDL, new SelectList(Enum.GetValues(typeof(myProject.Models.feedbackDDL))), "", new { @class = "ddl2" })
  • [How do you create a dropdownlist from an enum in ASP.NET MVC?](http://stackoverflow.com/questions/388483/how-do-you-create-a-dropdownlist-from-an-enum-in-asp-net-mvc) - if your not using MVC-5.1+, look at the 2nd answer –  Nov 01 '16 at 20:38

1 Answers1

1

try like this and see:

public enum feedbackDDL
    {
        [Description("General Information")] //System.ComponentModel
        GeneralInformation,
        feedback,
        [Display(Name = "Question Comments")] //System.ComponentModel.DataAnnotations
        QuestionComments
    }
James
  • 729
  • 6
  • 10