I have a strongly typed view which uses some client side validations written in Knockout. Problem is the validations have been bound to each control via the 'data-bind' property and hence I cannot display the data that is being fetched from the model. Here's a sample code:

@Html.TextBoxFor(m => m.Login, new { @placeholder = "Email", @class = "form-control",  data_bind = "css:{'has-error':EmailInValid()}, value: email" })

And the JS file includes methods like these for each control:

self.Validate = function () {
        var valid = true;
        toastr.clear();
        if (!self.email() || self.email() == '' || !self.http.EmailRegEx.test(self.email())) {
            toastr.error('Please enter a valid Email Address');
            valid = false;
            self.EmailInValid(true);
        } else { self.EmailInValid(false); }
}

How can I bind the value from model and apply the validation at the same time?

Related posts

Recent Viewed