0

code is:

@using (Html.BeginForm("Register", "User", FormMethod.Post, new { id = "RegisterForm" })) {

@Html.DropDownList("StateId", new SelectList(Model.States, "StateId", "StateName"), "--Select an option--", new { @tabindex = "11" })

}

i need required field validation for dropdown

2
  • 1
    Validate it how? Can you provide some more detail? Commented Jul 21, 2011 at 13:31
  • @yogee, show more code. What's the problem, and what have you tried? Commented Jul 21, 2011 at 13:36

1 Answer 1

1

Have you tried using Data Annotations in your model to mark the property as required?

[Required(ErrorMessage = "You must select a State")]

Are you exposing the StateId as a part of the Model? If so that's where you should set the Required Attribute, like so:

    [Required(ErrorMessage = "You must select a State")]
    public int StateId { get; set; }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.