I'm using unobtrusive client side validation for my current application but the problem is that it's not validating all fields but only some of them. First I thought that DropDownLists were the ones omitted by the validator, but after changing those for simple TextBoxes, I realized it's not working either. I really don't know what it is. So, I hope you can give me a hand:
I already have on my Web.Config:
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
I have the Metadata for one of the classes that is not working properly:
[MetadataType(typeof(QuestionMetadata))]
public partial class Question
{
[Bind(Exclude = "Id")]
public class QuestionMetadata
{
[Required]
public string Text { get; set; }
[Required]
[DisplayName("Question Type")]
public int QuestionType_Id { get; set; }
[Required]
[DisplayName("Category")]
public int Category_Id { get; set; }
[Required]
[Range(1,Int32.MaxValue)]
public int SortOrder { get; set; }
}
}
Finally the ViewCode:(Strongly-Typed and receives the ViewModel)
<asp:Content ID="Content2" ContentPlaceHolderID="JsContent" runat="server">
<script src="<%: Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/question-views.js") %>" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<h2 class="path"><%= ViewRes.Question.Create.PathCreate %></h2>
<% using (Html.BeginForm()) { %>
<%: Html.ValidationSummary(true) %>
<div>
<%: ViewRes.Question.Create.DropDownQuestionnaires %>
<%: Html.DropDownList("Questionnaire_Id", Model.questionnairesList, "--Select--")%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.question.Category_Id)%>
</div>
<div class="editor-field">
<%: Html.DropDownListFor(model => model.question.Category_Id, Model.categoriesList, "--Select--")%>
<%: Html.ValidationMessageFor(model => model.question.Category_Id)%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.question.QuestionType_Id)%>
</div>
<div class="editor-field">
<%: Html.DropDownListFor(model => model.question.QuestionType_Id, Model.questionsTypeList, "--Select--")%>
<%: Html.ValidationMessageFor(model => model.question.QuestionType_Id)%>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.question.Text)%>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.question.SortOrder)%>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.question.SortOrder)%>
<%: Html.ValidationMessageFor(model => model.question.SortOrder)%>
</div>
<p>
<input type="submit" value="<%: ViewRes.Shared.CreateButton %>" />
</p>
<% } %>
</asp:Content>
Thanks for any help.
code<div class="editor-label"> <label for="question_Category_Id">Category</label> </div> <div class="editor-field"> <select id="question_Category_Id" name="question.Category_Id"><option value="">--Select--</option> <option value=""></option> </select> <span class="field-validation-valid" data-valmsg-for="question.Category_Id" data-valmsg-replace="true"></span> </div> - met.lordcode<div class="editor-label"> <label for="question_QuestionType_Id">Question Type</label> </div> <div class="editor-field"> <select id="question_QuestionType_Id" name="question.QuestionType_Id"><option value="">--Select--</option> <option value="1">Selection Answers</option> <option value="2">Text Answers</option> </select> <span class="field-validation-valid" data-valmsg-for="question.QuestionType_Id" data-valmsg-replace="true"></span> </div> - met.lord