Home > DeveloperSection > Blogs > Custom Checkbox in ASP.Net MVC 4 Razor

Custom Checkbox in ASP.Net MVC 4 Razor

on    December-04-2012 1:16 AM

0 Comment(s)
 2715  View(s)
Rate this:

Custom Checkbox in ASP.Net MVC 4 Razor

Here I have described how to create custom checkbox in ASP.Net MVC 4. This custom checkbox support all browsers (Internet Explorer, Mozilla, Chrome, Opera and Safari) with latest updates. Stapes are given below

Step 1: Create controller (e.g. HomeController) and view (e.g. Index) in ASP.NET MVC 4.

Step 2: Copy and Paste below code on View page

<style type="text/css">



        opacity: 0;

        filter: alpha(opacity=0);




        background: transparent url('../images/checkbox1.png') 0 1px no-repeat;

        display: inline-block;

        border: 1px solid black;

        width: 23PX;

        height: 23px;




        background-position: 0 -28px;



<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script type="text/javascript">

    (function ($) {

        $.fn.ezMark = function (options) {

            options = options || {};

            var defaultOpt = {

                checkboxCls: options.checkboxCls || 'ez-checkbox',

                checkedCls: options.checkedCls || 'ez-checked', selectedCls: options.selectedCls || 'ez-selected',

                hideCls: 'ez-hide'


            return this.each(function () {

                var $this = $(this);

                var wrapTag = $this.attr('type') == 'checkbox' ? '<div class="' + defaultOpt.checkboxCls + '">' : '<div class="' + defaultOpt.radioCls + '">';

                // for checkbox

                if ($this.attr('type') == 'checkbox') {

                    $this.addClass(defaultOpt.hideCls).wrap(wrapTag).change(function () {

                        if ($(this).is(':checked')) {



                        else { $(this).parent().removeClass(defaultOpt.checkedCls); }


                    if ($this.is(':checked')) {








<script type="text/javascript">

    $(function () {

        $('.defaultP input').ezMark();

        $('.customP input[type="checkbox"]').ezMark({ checkboxCls: 'ez-checkbox-green', checkedCls: 'ez-checked-green' })






            <span class="defaultP">

                <input type="checkbox" name="avadhesh" value="1" id="chkid" checked="checked" style="width: 23px;

                    height: 23px; margin-left: -1px; margin-top: -1px;" /></span>







Step3: create a folder (e.g. Images) in project Solution Explorer paste below image within this folder. For copy below image, right click on image and save in your local drive.


Step4: change image path in CSS tag.

I hope you enjoy this blog.

Recent Activities

Barbara Jones added new Question What is ANR?   2 days ago

Kamlakar Singh added new Blog Convert Text Document to PDF File   16 days ago

Kamlakar Singh added new Article Introduction to Backbone.js   16 days ago

Don't want to miss updates? Please click the below button!