nav100
nav100

Reputation: 411

validate DropdownlistFor help

I couldn't get this code working. It's not displaying validation error message when I submit the form.

viewModel

    [Required] 
    public SelectList CountryList { get; set; }
    public string Country { get; set; }

Create.aspx

    <%= Html.DropDownListFor(m => m.Country,Model.CountryList, "--Select--")%>
        <%: Html.ValidationMessageFor(model => model.Country,"*") %>

Upvotes: 1

Views: 749

Answers (1)

Tassadaque
Tassadaque

Reputation: 8199

Try this

public SelectList CountryList { get; set; }
[Required]  
public string Country { get; set; }

Upvotes: 2

Related Questions