Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

KnockOut controls not working with model data annotations.

75 views
Skip to first unread message

Dileepreddy Sobha Krishna

unread,
May 25, 2015, 10:01:43 AM5/25/15
to knocko...@googlegroups.com
Hi,

Below is the mark-up of my mvc-View and model.
The problem i am facing is , client validation is not firing for ko.Html.Textbox() control, but it is fine with normal Html.Textbox control.
Appreciate any solutions for this.

Thanks,
Dileep.

VIEW:
@using PerpetuumSoft.Knockout
@model MVCDemo.Models.EmployeeModel


@{
    var ko = Html.CreateKnockoutContext();
}

@{
    ViewBag.Title = "Home Page";
}
<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>

 @using (Html.BeginForm()) 
 {
        @Html.ValidationSummary(true)
        
        <fieldset>
            <legend>Fields</legend>
            
            <div class="editor-label">
                @Html.LabelFor(model => model.Id)
            </div>
            <div class="editor-field">
                @ko.Html.TextBox(model => model.Id)                
                @Html.ValidationMessageFor(model => model.Id)
            </div>
            
            <div class="editor-label">
                @Html.LabelFor(model => model.Name)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.Name)
                @Html.ValidationMessageFor(model => model.Name)
            </div>
            
            <div class="editor-label">
                @Html.LabelFor(model => model.Address)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.Address)
                @Html.ValidationMessageFor(model => model.Address)
            </div>
            <p>
          
                <input type="submit" value="Update" />
            </p>
        </fieldset>
    }

MODEL:
 public class EmployeeModel
    {
        [Required]
        public int Id { get; set; }

        [Required]
        public string Name { get; set; }

        [Required]
        public string Address { get; set; }
    }

ClientValidation-using_DataAnnotations.png
Reply all
Reply to author
Forward
0 new messages