MVC-3/jQuery: stop validating my checkbox

2019-01-29 12:13发布

I have MVC-3 user control (html helper & aspx view engine). Some how when I submit the form jQuery un-obtrusive validation fires up & requires me to check all checkboxes. How do I prevent it?

Further Info:

1) There is no required attribute in my model.

2) I am using this check-box inside telerik gridview

    namespace Alpha.Views
    {
        public class AlphaCheckBoxControl : ViewUserControl<AlphaCheckBox> { 
    }

    public class AlphaCheckBox
    {
        public bool isChecked;
        public string name { get; set; }
        public MvcHtmlString labelText;
        public bool readOnly;
        public bool visible { get; set; }

        public IDictionary<string, object> htmlAttributes()
        {
            var dict = new Dictionary<string, object>();

            if (readOnly) dict.Add(@"readonly", "readonly");
            if (readOnly) dict.Add("disabled", "disabled");
            return dict;
        }
    }  
}


<%@ Control Language="C#" Inherits="Alpha.Views.AlphaCheckBoxControl" 
        AutoEventWireup="True" CodeBehind="AlphaCheckBox.ascx.cs" %>


<tr>
      <td>
          <%= Html.Label(Model.name)%>
      </td>
      <td>
           <%= Html.CheckBox(Model.name, Model.isChecked, Model.htmlAttributes())%>
      </td>
  </tr>

0条回答
登录 后发表回答