lundi 21 août 2017

Listing Products with Checkbox

My question is about listing products with using checkbox which comes from database.I want the products to show when onclick event of checkbox.I don't want to use "submit button".

<script type="text/javascript">

function getUrun(urunId) {
    $.getJSON("/Products/getProduct/" + urunId, null,

    function (data) {
        items = "";
        $.each(data, function (i, getProduct) {

            items += "<p>" + getProduct + "</p>";
        }
             )
        $('#urunler').html(items);
    }

) };

        $.ajax({
            type: 'GET',
            url: '/Products/CategoryProducts/?cat=' + urunId,
            success: function (result) {
                $("#urunler").html(result)

            },
            error: function () {
                alert('Error.');
            }
        }).done( function () {
            $("#thisButton").show();
        });

    ;

   public JsonResult getProduct(int id)
    {
        ViewModel vm = new ViewModel();
        vm.product = (from z in db.Product
                      where (z.category_id==id)
                      select z).ToList();
        return Json(vm, JsonRequestBehavior.AllowGet);

    }



<label class="checkbox"><input type="checkbox" name="checkbox" onclick="getUrun(this.value)" checked="checked=@item.category_id==@cat" value="@item.category_id"><i></i>@item.category_name</label>

I've tried to do with json and ajax, but it didn't work.

The result is null




Aucun commentaire:

Enregistrer un commentaire