2017-05-19 65 views
1

我已经实现了对我的MVC视图的必需验证。文本控件显示验证消息,但是kendo组合框没有。我正在做一个ajax回发。Kendo Combobox无需触发验证消息

为什么comboxbox doest显示消息的任何原因?工作类型组合是必需的,但不显示验证消息。

enter image description here

查看

@using (Ajax.BeginForm("ActivityWorkLog_Create", "Activity", new AjaxOptions 
{ 
    HttpMethod = "POST", 
    OnSuccess = "OnWorklogStatusSuccess", 
    OnFailure = "OnWorklogStatusFailure" 
}, new { id = "workLogForm" })) 
{ 

<div class="k-popup-edit-form k-window-content k-content" data-role="window"> 
    <div class="k-edit-form-container"> 
     @Html.HiddenFor(x => x.RequestID, new { data_bind = "value: requestId" }) 
     @Html.HiddenFor(x => x.ActivityID, new { data_bind = "value: activityId" }) 
     @Html.HiddenFor(x => x.CountryCode, new { data_bind = "value: countryCode" }) 

     <div class="form-group"> 
      <div class="editor-label"> 
       @Html.LabelFor(model => model.WorkLogAppliesToName) 
      </div> 
      <div class="editor-field"> 
       @(Html.Kendo().ComboBoxFor(model => model.WorkLogAppliesToName) 
     .Name("WorkLogAppliesToID") 
     .Filter("contains") 
     .HtmlAttributes(new { style = "width:300px", @readonly = "readonly" }) 
     .Placeholder("Select...") 
     .DataTextField("WorkLogAppliesToName") 
     .DataValueField("WorkLogAppliesToID") 

     .DataSource(dataSource => dataSource 
      .Read(read => read.Action("GetWorkLogAppliesTo", "WorkLog", new { id = 0 }).Type(HttpVerbs.Post) 
      ) 

     ) 
       ) 
       @Html.ValidationMessageFor(model => model.WorkLogAppliesToName, "", new { @class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      <div class="editor-label"> 
       @Html.LabelFor(model => model.ActivitySLA) 
      </div> 
      <div class="editor-field"> 
       @*@Html.EditorFor(model => model.ActivitySLA)*@ 
       @Html.TextBoxFor(model => model.ActivitySLA, new { id = "ActivityDesc", @readonly = "readonly", Class = "textBoxFor" }) 

      </div> 
     </div> 

     <div class="form-group"> 
      <div class="editor-label"> 
       @Html.LabelFor(model => model.ActivityID) 
      </div> 
      <div class="editor-field"> 
       @(Html.Kendo().ComboBoxFor(model => model.ActivityID) 
    .Name("Activity") 
    .Filter("contains") 
    .HtmlAttributes(new { style = "width:300px", @readonly = "readonly" }) 
    .Placeholder("Select...") 
    .DataTextField("Description") 
    .DataValueField("ActivityID") 

    .DataSource(dataSource => dataSource 
     .Read(read => read.Action("GetActivity", "WorkLog").Data("additionalActivityInfo").Type(HttpVerbs.Post) 
     )//.ServerFiltering(true) 
    )//.CascadeFrom("ServiceID").Filter("contains") 

       ) 
       @Html.ValidationMessageFor(model => model.ServiceID, "", new { @class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      <div class="editor-label"> 
       @Html.LabelFor(model => model.WorkLogType) 
      </div> 
      <div class="editor-field"> 
       @(Html.Kendo().ComboBoxFor(model => model.WorkLogTypeCode) 
    .Name("WorkLogTypeCode1") 
    .Filter("contains") 
    .HtmlAttributes(new { style = "width:300px"}) 
    .Placeholder("Select...") 
    .DataTextField("WorkLogType") 
    .DataValueField("WorkLogTypeCode") 
    .DataSource(dataSource => dataSource 
    .Read(read => read.Action("GetWorkLogType", "WorkLog").Data("additionalWLTInfo").Type(HttpVerbs.Post)) 
    ) 

       ) 
       @Html.ValidationMessageFor(model => model.WorkLogTypeCode, "Please select a worklog type", new { @class = "text-danger" }) 
      </div> 
     </div> 

     <div class="form-group"> 
      <div class="editor-label"> 
       @Html.LabelFor(model => model.WorkLogSubject) 
      </div> 
      <div class="editor-field"> 
       @Html.EditorFor(model => model.WorkLogSubject) 
       @Html.ValidationMessageFor(model => model.WorkLogSubject, "", new { @class = "text-danger" }) 
      </div> 
     </div> 
     <div class="form-group"> 
      <div class="editor-label"> 
       @Html.LabelFor(model => model.WorkLogDetails) 
      </div> 
      <div class="editor-field"> 
       @Html.TextAreaFor(model => model.WorkLogDetails, new { htmlAttributes = new { @class = "form-control", cols = "50" } }) 
       @Html.ValidationMessageFor(model => model.WorkLogDetails, "", new { @class = "text-danger" }) 
      </div> 
     </div> 

      <div class="worklogStatusButtonAlign"> 
       <button id="btnWorkLogSave" type="submit" class="k-button k-button-icontext k-primary k-grid-update">Save</button> 
       <button id="btnClose" type="button" class="k-button k-button-icontext k-grid-cancel">Cancel</button> 

      </div> 

      <div id="worklogStatusMessage"> </div> 

     </div> 
</div> 
} 

Javacript

<script> 

      $(document).ready(function() { 



       var form = $("#workLogForm") 
         .removeData("validator") 
         .removeData("unobtrusiveValidation"); 
       $.validator.unobtrusive.parse(form); 


      }); 

视图模型

public class ActivityWorkLogViewModel 
{ 
     [ScaffoldColumn(false)] 
     [Display(Name = "WorkLogID", ResourceType = typeof(Resources.Resource))] 
     public int WorkLogID { get; set; } 

     [Required(ErrorMessage = "WorkLogType is required")] 
     [Display(Name = "WorkLogTypeCode", ResourceType = typeof(Resources.Resource))] 
     public string WorkLogTypeCode { get; set; } 


     [Display(Name = "WorkLogType", ResourceType = typeof(Resources.Resource))] 
     public string WorkLogType { get; set; } 
     [Required] 
     [Display(Name = "WorkLogAppliesToID", ResourceType = typeof(Resources.Resource))] 
     public int WorkLogAppliesToID { get; set; } 
     [Display(Name = "WorkLogAppliesToName", ResourceType = typeof(Resources.Resource))] 
     public string WorkLogAppliesToName { get; set; } 
     [Required] 
     [Display(Name = "RequestID", ResourceType = typeof(Resources.Resource))] 
     public int RequestID { get; set; } 
     [Display(Name = "ServiceID", ResourceType = typeof(Resources.Resource))] 
     public Nullable<int> ServiceID { get; set; } 
     [Display(Name = "ActivityID", ResourceType = typeof(Resources.Resource))] 
     public Nullable<int> ActivityID { get; set; } 
     [Required(ErrorMessage = "Subject is required")] 
     [Display(Name = "WorkLogSubject", ResourceType = typeof(Resources.Resource))] 
     public string WorkLogSubject { get; set; } 
     [Required(ErrorMessage = "Details is required")] 
     [Display(Name = "WorkLogDetails", ResourceType = typeof(Resources.Resource))] 
     public string WorkLogDetails { get; set; } 
     [Display(Name = "EmailTo", ResourceType = typeof(Resources.Resource))] 
     public string EmailTo { get; set; } 
     [Display(Name = "IsActive", ResourceType = typeof(Resources.Resource))] 
     public bool IsActive { get; set; } 
     [Display(Name = "CountryCode", ResourceType = typeof(Resources.Resource))] 
     public string CountryCode { get; set; } 
     [Display(Name = "ActivitySLA", ResourceType = typeof(Resources.Resource))] 
     public string ActivitySLA { get; set; } 
} 

回答

1

尝试添加此:

<script> 
    $(function() { 
     $("form").kendoValidator(); 
    }); 
</script> 

和/或:

<script> 
    $.validator.setDefaults({ 
     ignore: "" 
    }); 
</script>