Validating Empty Dropdownlist

Asked

Viewed 222 times

1

I have the following Dropdownlist:

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

When seventh '0' in his value it is empty. I would like to validate whether Dropdown is set to zero or not and display a message forcing the user to select some value. What I must do?

1 answer

2


What should I do?

Mark the property of Model with [Required]:

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.