Fahad
Fahad

Reputation: 173

Ajax not triggering for Partial view

I am adding Partial view in to my main view , the partial view code snippet is:

<li class="item-@j deeper parent active">
        <a class="" href="">
            <span data-toggle="collapse" data-parent="#menu-group-1" href="#sub-item-@j" class="sign"><i class="icon-plus icon-white"></i></span>
            <span class="lbl">Brands</span>
        </a>
        <ul class="children nav-child unstyled small collapse" id="sub-item-@j">
            @foreach (var brand in Model.BrandList)
            {
                <li class="item-@j deeper parent active">
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" value="@brand._id">
                            @*<a class="" href="@Url.Action("FilterData", "ShopWindow", new {shopKey=house._id,houseKey=house._id,houseName = house.House})">*@
                            <span class="lbl">@brand.Brand</span>
                            @*</a>*@
                        </label>
                    </div>
                </li>
                j++;
            }
        </ul>
    </li>

in my main view I have a script to get all the check boxes that user have selected, the script snippet :

<script type="text/javascript">
      var selectedBrand=[];


    $("input[type='checkbox']").change(function () {
          $('#brand input:checked').each(function () {
            selectedBrand.push($(this).attr('value')); 
            alert("Test");
        })
        sendAjaxRequest();


    });

When I select any check box from the partial view the script's change function is not getting triggered. This change function triggers if I check any checkbox in the main page but not for checkboxes belongs to partial view .

Any idea?

Thanks

Upvotes: 0

Views: 73

Answers (1)

Fahad
Fahad

Reputation: 173

I found the solution :

changed

$("input[type='checkbox']").change(function () {

to

 $(document).on('change', '.checkbox', function() {

Upvotes: 1

Related Questions