Change default error message "The value ... is not valid for..."

This is my solution. Tested on MVC 3 and MVC 4.

  1. Create App_GlobalResources folder in project (easy way is right click to project -> Add -> Add ASP.NET folder -> App_GlobalResource).
  2. Add a resx file to App_GlobalResources (e.g. YourResource.resx).
  3. Add resource key "PropertyValueInvalid". By default, the message is "The value {0} is not valid for {1}". You can change or translate whatever you want.
  4. Add the code DefaultModelBinder.ResourceClassKey = "YourResource" to Application_Start function in Global.asax.

Posted in | Leave a comment

Show spinner on load image.

Click on links to see spinner on load image.

Show image 1
Show image 2
Show image 3
function changeImg(url) {
    var img = document.getElementById('previewImg');
    var spinner = document.getElementById('spinner');
    // show spinner
    spinner.style.display = '';
    img.style.display = 'none';
    img.onload = function() {
        spinner.style.display = 'none';
        this.style.display = '';
        this.onload = null;
    }
    img.src = url;
}  

Posted in | Leave a comment

Resize image and keep aspect ratio.

Width:
Height:

Javascript

function Resize(img) { var w = document.getElementById('t1').value; var h = document.getElementById('t2').value; var d = document.getElementById('d1'); d.style.width = w + 'px'; d.style.height = h + 'px'; img.style.width = 'auto'; img.style.height = 'auto'; if(img.width / img.height >= w / h) { img.style.width = d.style.width; } else { img.style.height = d.style.height; } }

Posted in | Leave a comment

Search

Swedish Greys - a WordPress theme from Nordic Themepark. Converted by LiteThemes.com.