lundi 11 janvier 2016

Pass the Multiple checkbox values through form serialize and using ajax

I trying to create a CRUD Operations using ajax in mvc.. I trying to pass the checkbox values through form serialize and using ajax. The multiple check box values is not working but single checkbox value is stroed in the grid..

When i trying to save the multiple checkbox values to database. but its not saving.. when i click the two checkbox values but its saving only one checkbox values in the database. How to save the multiple checkbox values using comma seperated?

Give me one solution..

Thanks, Pari

Index.cshtml

 function SaveEmployee() {

        var EmployeeDetails = $("#frmemployee").serialize();//JSON Serialization
        $.post("/Home/Create", EmployeeDetails, function (data) {
            if (data == 0) {
                location = location.href;
            }
            else {
                var tablename = $("#tableemployee");

                var testval = [];
                $('[name="hobbies"]:checkbox:checked').each(function () {
                    testval.push($(this).val());
                });

                var TableData = "<tr>" +
                       "<td>" + data.EmployeeName + "</td>" +
                       "<td>" + data.EmployeeAddress + "</td>" +
                       "<td>" + data.EmployeeSalary + "</td>" +
                       "<td>" + data.Country + "</td>" +
                       "<td>" + data.DOB + "</td>" +
                       "<td>" + data.Gender + "</td>" +
                       "<td>" + testval  + "</td>" +
                       "<td>" + "" + "</td>" +
                       +"</tr>";

                tablename.append(TableData);
                $("#myModalEmployee").modal('hide');
                //window.location.reload(true);
            }
        }, 'json');
    }




Aucun commentaire:

Enregistrer un commentaire