Validating Empty DropDownList

1

I have the following DropDownList:

@Html.DropDownList("HorasPendenciaID", null, new { @class = "dropdown-custom" })

When you ' 0 ' in your value it is empty. I would like to validate if the DropDown is set to zero or not and display a message forcing the user to select some value. What should I do?

    
asked by anonymous 14.09.2016 / 16:28

1 answer

2
  

What should I do?

Check the Model property with [Required] :

[Required]
public int HorasPendenciaID { get; set; }

If the validation messages are in English, install this NuGet package .

    
14.09.2016 / 16:33