Monthly Archives: March 2015

Knockout.js logo

knockout.js: Your observable isn’t seeing changes made to text controls until they lose focus

knockout is great library that’s easy to use. One thing I noticed is that changes made in text-controls are only propagated to the observable once that control loses focus.

If you want changes in a text-control to immediately be reflected in your observable, then avoid the value binding and use the textInput binding like below:

<input data-bind="textInput: Name" type="text" value="" />
<script type="text/javascript">
    $(document).ready(function () {
        viewModel = ViewModel()
        ko.applyBindings(viewModel);

    });
    function ViewModel() {
        var self = this;
        self.Name = ko.observable("");
    }
</script>

Entity Framework and the error: Cannot attach the file ‘xxx.mdf’ as database ‘xxx’

Say you’re working on a project that’s using Entity Framework to manage the database storage in a SQL Server Express installation. If you delete the .mdf file you’ll keep on getting the error” Cannot attach the file 'xxx.mdf' as database 'xxx'.

To solve it, in visual studio go to the Package Manager console and run the following commands:

sqllocaldb.exe stop v11.0
sqllocaldb.exe delete v11.0
Update-Database