This is a migrated thread and some comments may be shown as answers.

[Solved] Client side validation on a DropDownList

1 Answer 152 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
russ
Top achievements
Rank 1
russ asked on 18 Jul 2011, 08:42 AM
I'm following the example to add a 'null' option to a drop down list from here. Eg. I have something like this to add the null option

<%
        var list = new SelectList(Model.Products, "ProductID", "ProductName").ToList();
        list.Insert(0, new SelectListItem { Text = "Select option...", Value = "-1" });
    %>
  
    <%= Html.Telerik().DropDownListFor(model => model.PersonId)
            .SelectedIndex(0)
            .BindTo(list)
    %>

In my case the DropDownList is for a required model property.  Client-side validation isn't preventing people from submitting the form.  How would I go about adding the client side validation myself?

Thanks,
Russ



1 Answer, 1 is accepted

Sort by
0
Mac
Top achievements
Rank 1
answered on 19 Nov 2011, 11:31 AM
Hi russ,

One approach may be to use the Min Data Validation Extension from here: http://dataannotationsextensions.org/Min/Create

Implement the following on the model being edited for ProductID, or PersonID, whichever is appropriate:

[Min(1, ErrorMessage = "Product is Required")]

Thanks,
Calvin
Tags
ComboBox
Asked by
russ
Top achievements
Rank 1
Answers by
Mac
Top achievements
Rank 1
Share this question
or