Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is my Model :

public partial class TAUX
    {
        ....
        [Required(ErrorMessage="Select one At least")]
        public IEnumerable<short> SelectItems { set; get; }
    }

This is my View :

@model pfebs0.Models.TAUX
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="/Scripts/chosen.jquery.js" type="text/javascript"></script>
<link href="/Content/chosen.css" rel="stylesheet"  type="text/css" />
...
            $(".chosen-select").chosen({ width: "100%"})
</script> 
...
            @Html.ListBoxFor(model => model.SelectItems, (ViewBag.CAT_ID as SelectList), new { @class = "chosen-select", data_placeholder = "Selection une Categorie..." })
            @Html.ValidationMessageFor(model => model.SelectItems)

Client Validation dosn't work in my ListBox , but for other Attribute it works fine. How to fix it ?

share|improve this question
    
This question has already been answered [here][1]. [1]: stackoverflow.com/questions/6428907/… –  Jason Nesbitt May 14 '14 at 14:47
    
No I want Client Validation –  Chlebta May 14 '14 at 14:50
    
You really should have jQuery.validate.unobtrusive in your bundles.. However, do you also have jQuery.Validate.js included somewhere? –  Erik Funkenbusch May 14 '14 at 14:57
    
yeah It's included in my parent View and I tried to add it in partial view but always the client side validation not working –  Chlebta May 14 '14 at 14:59
1  
Ahh.. Actually, I bet it is... The problem is that you're using chosen.jquery, which actually hides your real listbox, and creates a fake one, which most likely doesn't work with validation. Try not using the chosen and see if it works. –  Erik Funkenbusch May 14 '14 at 15:03

1 Answer 1

@Html.ValidationMessageFor(model => model.CAT_ID)

change to

@Html.ValidationMessageFor(model => model.SelectItems)

share|improve this answer
    
This dosn't work Validation work's only for Server Side –  Chlebta May 14 '14 at 14:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.