You can subscribe to the change of the username observable on your viewmodel and issue ajax request to the controller that will return the bool.
Something like this
1) Your view model
function registrationViewModel() {
var self = this;
self.username = ko.observable();
self.usernameUniqueue = ko.observable(true);
self.username.subscribe (function() {
$.ajax({
url: '/registration/isusernameuniqueue',
data: { username: self.userName() },
type: 'POST',
success: function(result) {
self.usernameUniqueue(result);
}
});
});
}
ko.applyBindings(new registrationViewModel())
2) Your view
<input type="text" data-bind="value: username" />
<span data-bind="visible: !usernameUniqueue()" style="display:none">user name not uniqueue</span>
3) Your controller
public class Registration : Controller
{
[HttpPost]
public ActionResult IsUsernameUniqueue(string username)
{
// make a check here and return true or false...
return Json(/*true or false*/);
}
}