KnockoutJS Unobtrusive Validation with ASP.NET MVC

Knockout JSASP.NET MVC has a really nice capability of generating client-side validation code based on the data annotations on your model. It can either generate a JavaScript code with the rules or generate data attributes on the input elements (unobtrusive). By using the second approach jQuery can read these data attributes (by the unobtrusive validation plugin) and automatically wire the validation logic up on the client. All this works great if you have a completely standard application – a user enters some input data and sends it to the server. However, if your application also requires some client-side logic along, you may consider KnockoutJS. The basic functionality of KnockoutJS, however, is not enough when input from the user is required. Fortunately, there is a plugin, which adds validation capabilities to KnockoutJS. It provides a set of rules like min, max, equals, etc., which we can use out of the box. Now the issue is how to make the data attributes, generated by ASP.NET MVC, and KnockoutJS validation play together. As I couldn’t find anything out of the box, I decided to create my own plugin. Continue Reading…