-1

I want to create custom Html Helper for my model that contains multiple attribute (50 label, 20 textbox, 5 dropdown list, 6 checkbox, ...) which there is some their type is Enum:

This is my Enum Class:

    public enum ClassType
    {
        variable1, 
        variable2,
        ...
    } 

This is The model that contains an Enum attribute:

 public class Test2Models
    { 
        [Required]
        [Display(Name = "SelectList")]
        public ClassType InitialValue2 { get; set; } 
        ...
    }

Now i want to create a custom Html Helper in which i will give the InitialValue2 and i want him to return all the attributes.

 public static MvcHtmlString Form<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression }
{
///
}

To be more clear i want the call of my custom Html Helper like this:

@html.form(it=>it.InitialValue2) 

and the result i want a list of input

Could you help me please?

1 Answers1

1

Take a look at the Enum.GetValues() you can leverage this method to get a list of available options for your enum depending on the type

Jordy van Eijk
  • 2,718
  • 2
  • 19
  • 37