0

我對當前的應用程序使用不顯眼的客戶端驗證,但問題在於它不驗證所有字段,只驗證其中的一部分。首先,我認爲DropDownLists是驗證器省略的,但是在更改簡單TextBoxes之後,我意識到它也不起作用。我真的不知道它是什麼。所以,我希望你能夠給我一個手:ASP.NET MVC3客戶端驗證幫助

我已經在我的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:(強類型和接收視圖模型)

<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> 

感謝您的幫助。

+0

代碼生成領域沒有驗證正確:'code'

\t
\t

+0

代碼爲沒有正確驗證的字段生成:'代碼'

\t
\t

+0

看起來問題和類別都是*不*驗證,正確(我認爲您在其他地方說其中一個正在驗證...以下是選擇(需要和數字)應生成的內容: