Click here to Skip to main content
15,908,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am able to loop through the div element with the particular class and get the data.

But I would like to save the data in a collection or Array and pass them via jQuery Ajax to asp.net mvc application.

What I have tried:

<div id="photoDiv">
        <div id="pcbox-mustang.jpg" class="box box2PerRow imgbox">
            <div class="tools" id="t-0">
                <span id="e-mustang.jpg" class="glyphicon glyphicon-check imgEmail"></span>
                <span id="d-mustang.jpg" class="glyphicon glyphicon-minus-sign trashicon"></span>
                <span id="r-mustang.jpg" class="glyphicon glyphicon-arrow-down imgRotate"></span>
                <p>Mustang</p>
            </div>
        </div>
        <div id="pcbox-mustang.jpg" class="box box2PerRow imgbox">
            <div class="tools" id="t-0">
                <span id="e-bmw.jpg" class="glyphicon glyphicon-check imgEmail img-checked"></span>
                <span id="d-bmw.jpg" class="glyphicon glyphicon-minus-sign trashicon"></span>
                <span id="r-bmw.jpg" class="glyphicon glyphicon-arrow-down imgRotate"></span>

                <p>BMW</p>
            </div>
        </div>
        <div id="pcbox-mustang.jpg" class="box box2PerRow imgbox">
            <div class="tools" id="t-0">
                <span id="e-audi.jpg" class="glyphicon glyphicon-check imgEmail img-checked"></span>
                <span id="d-audi.jpg" class="glyphicon glyphicon-minus-sign trashicon"></span>
                <span id="r-audi.jpg" class="glyphicon glyphicon-arrow-down imgRotate"></span>
            </div>

            <p>Audi</p>
        </div>
    </div>
    <div id="imgDownloadDivId" style="margin-left:15px;text-align:left; padding-bottom:15px;">
        <button id="imgDownloadId" type="button" class="btn btn-primary">Download</button>
    </div>

    <script>

        $(document).ready(function () {

            $(document).on('click', '#imgDownloadId', function () {
               
                $(".img-checked").each(function (index) {

                    var imageID = $(this).prop("id");
                    var imagename = imageID.substring(2);
                    var imgSourcePath = "\\MyProject\\Images\\Cars\\" + imagename
                });

            })

        })
       
    </script>
Posted
Updated 16-Feb-18 6:57am

1 solution

Something like this:
JavaScript
$(document).on('click', '#imgDownloadId', function (e) {
    e.preventDefault();
    
    var data = [];
    
    $(".img-checked").each(function (index) {
        var imageID = $(this).prop("id");
        var imagename = imageID.substring(2);
        var imgSourcePath = "\\MyProject\\Images\\Cars\\" + imagename;
        data.push(imgSourcePath);
    });
    
    // Send the data to the server here...
});
 
Share this answer
 
Comments
istudent 16-Feb-18 18:14pm    
I am having problem passing string array from ajax to mvc action method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900