Client Side Form validation in ASP.NET MVC

Client side form validation increases User friendliness. User doesn’t want to wait for page refresh and see form validation errors.

In ASP.NET MVC we can validate using Data Annotation. So we can use these validation to client side validation. No more huge validation codes.

We can use Jquery validation plugin comes with ASP.NET MVC. This bundle is not referenced in _layout.cshtml by default. We have to add it manually.

Watch youtube video 

Download source code

 

Find Bootstrap screen size in Javascript

Some times we want to know bootstrap screen size from javascript. When I am developing I needed it and Now I am using following function. Calling it I can get bootstrap screen size like “xs”,”md”,”sm”,”lg”


function findBootstrapEnvironment() {
var envs = ['xs', 'sm', 'md', 'lg'];

$el = $('
<div>');
$el.appendTo($('body'));

for (var i = envs.length - 1; i >= 0; i--) {
var env = envs[i];

$el.addClass('hidden-' + env);
if ($el.is(':hidden')) {
$el.remove();
return env
}
};
}

Bootstrap loading effects in button

It is nice to show loading behavior to user and let user no something is happening which take some time and avoid touching UI.

In bootstrap it is very simply task.

I think it might help you

$(this).button(‘loading’) shows loading text in button. we tell this to bootstrap by using data-loading-text=”Loading…” 

When finishing our long runing logic we can call

$(this).button(‘reset’);

This will bring button to original state.