Kendo MVC validator always gives postback?

2 posts, 0 answers
  1. Marco
    Marco avatar
    20 posts
    Member since:
    May 2011

    Posted 04 Nov 2013 Link to this post


    Maybe I just do not understand or I made some mistakes but:

    When using the validator in combination with a plain MVC form, the page always posts to the server. That kinda surprised me. I assumed with the correct annotations on the model, the client side validation should occur first and the page should never do a postback when the form is invalid.

    I solved that by setting the required attribute on each html input element.
    It seems a little strange I have to add on both the model and in the view a required flag. Or am I missing something?

    Here is my example: 

    public class LoginViewModel : BaseViewModel
            public LoginModel Model { get; set; }
    public class LoginModel
            [Required(ErrorMessageResourceName="Generic_Error_IsRequired", ErrorMessageResourceType=typeof(App_GlobalResources.Resource))]
            [Display(Name="Login_Username", ResourceType=typeof(App_GlobalResources.Resource))]
            public string UserName { get; set; }
            [Required(ErrorMessageResourceName = "Generic_Error_IsRequired", ErrorMessageResourceType = typeof(App_GlobalResources.Resource))]
            [Display(Name = "Login_Password", ResourceType = typeof(App_GlobalResources.Resource))]
            public string Password { get; set; }
            [Display(Name = "Login_Remember_me", ResourceType = typeof(App_GlobalResources.Resource))]
            public bool RememberMe { get; set; }

    @model Gusto.Web.ViewModels.LoginViewModel
        ViewBag.Title = @Resources.Resource.Login_Page_Title; 
    <div class="form-vertical login">
        <!-- BEGIN LOGO -->
        <div class="logo">
    @using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }))
        <div id="login-form">
        <div class="status"></div>
                <div class="control-group">           
                        @Html.LabelFor(m => m.Model.UserName, new { @class="control-label"})
                    <div class="controls">   
                        @Html.EditorFor(m => m.Model.UserName, new { @required="required" })
                        @Html.ValidationMessageFor(m => m.Model.UserName)
                <div class="control-group">           
                    @Html.LabelFor(m => m.Model.Password)
                    @Html.PasswordFor(m => m.Model.Password, new { @required="required" })
                    @Html.ValidationMessageFor(m => m.Model.Password)
                <div class="control-group">           
                    @Html.CheckBoxFor(m => m.Model.RememberMe)
                    @Html.LabelFor(m => m.Model.RememberMe, new { @class = "checkbox" })
            <input type="submit" class="btn green pull-right" value="Login" id="btnSubmit" />
            @Html.ActionLink("Register", "Register") @Resources.Resource.Login_Register
    @section Scripts {
        <script type="text/javascript">       
            $(document).ready(function () {         
                var validator = $("#login-form").kendoValidator().data("kendoValidator"), status = $(".status");
                $("#btnSubmit").click(function () {
                    if (validator.validate()) {
                    } else {

  2. Sebastian
    Sebastian avatar
    9934 posts

    Posted 05 Nov 2013 Link to this post

    Hello Marco,

    It looks you found the cause of the abnormality and the solution for it here. I am closing this thread to avoid forks in the communication which appears to be on the same subject.

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top