Я использую ненавязчивую проверку на стороне клиента для моего текущего приложения, но проблема в том, что она проверяет не все поля, а только некоторые из них. Сначала я подумал, что DropDownLists были пропущены валидатором, но после изменения их для простых текстовых полей я понял, что это тоже не работает. Я действительно не знаю, что это такое. Итак, я надеюсь, что вы можете дать мне руку:
У меня уже есть в моем Web.Config:
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
У меня есть метаданные для одного из классов, который не работает должным образом:
[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; }
}
}
Наконец, ViewCode: (строгий тип и получает 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>
Спасибо за любую помощь.
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› - person met.lord   schedule 07.07.2011code
‹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›Выбор ответов‹/option› ‹option value=2›Текстовые ответы‹/option› ‹/select› ‹span class=field- допустимые данные-valmsg-for=question.QuestionType_Id data-valmsg-replace=true›‹/span› ‹/div› - person met.lord   schedule 07.07.2011