Welcome...



...All those moments will be lost in time, like tears in rain....

- soliloquy from Blade Runner


Bits and bytes do get lost, awash in the rain of data flow that is Internet. They slip away from us, never to found again... some of them will be captured here, many more will not... like tears in rain...



Thursday, October 31, 2013

Knockout and ()

  I have to put post-it note somewhere:

  PUT ( ) on every binding that's part of the expression!

 It's so misleading - if you have regular  data binding to the something like this:

<div data-bind="text: customer.name"></div>

 that works without parenthesis.

 If you have expression, don't forget your ()!


'class': $root.currentColor().name() === $data.name() ? ...

Bootstrap

 Looks like there was an error in bootstrap 3.0 that lead to font not being displayed in certain browsers. Version 3.01 fixed that, but to get Chrome to display .woff font, I had to add Mime type to the IIS:

File name extension:
.woff

Mime type:
application/x-woff

IIS 7.5 and mapped share

Virtual directory on IIS 7.5 pointing to shared folder on the network, containing pictures...  and strange error message about my config file being corrupt.

Google-fu for:

500.19 IIS 7.5 0x80070003

yielded finally proper solution - you can't use network mapped drive when you define virtual directory for IIS; you have to use \\SERVER\Share type of syntax.

Nothing to do with config files!

To get proper 500 error resolution, look for the code like 0x80070003 on the page, not just 500.19... there are many many codes related to that error.

Tuesday, October 29, 2013

JavaScript error handling

 JavaScript does have try catch but it has something even handier for error catching - window.onerror.

 It used not to work on Chrome (yes, really!) and since now it works in pretty much all browsers, it's very convinient for error handling.

 Basically, it will redirect all console errors to your function.

 To get it to work, it has to be in its own script block (or it's own include file, the first one to be included).

<script type="text/javascript">
  window.onerror = function(msg, url, linenumber) {
        alert('Error message: ' + msg + '\nURL: ' + url + '\nLine Number: ' + linenumber);
}
</script>

Parameter (in order) Description
Error Message Contains a message explaining why the error occurred.
Error URL Contains the url of the page with the error script
Error Line Number Contains the line number where the error occurred

Tuesday, October 8, 2013

MVC - How to get ModelState collection in the View

ValidationSummary is nice way of displaying errors on the Model.
Sometimes it's useful to query ModelState collection itself, to see it's content.
This code will display all errors that are in collection.
Note: This is for Errors only, Exceptions are in different collection - item.Value.Exceptions...

<table>
  <tr><td>Model State</td></tr>
    @foreach (var item in ViewContext.ViewData.ModelState)
    {
        if (item.Value.Errors.Any())
        {
            <tr>
                <td><b>@item.Key</b></td>
                <td>@((item.Value == null || item.Value.Value == null) ? "<null>" : item.Value.Value.RawValue)</td>
                <td>In</td>
                <td>Error: @(string.Join("; ", item.Value.Errors.Select(x => x.ErrorMessage)))</td>
            </tr>
        }
    }
</table>