Manoz
Manoz

Reputation: 6587

Parameters with anchor href

Is this the right way of including parameter in anchor link?

 <a href="'/LedgerIndex/PDF/?AccID='+ '@Model.Item1.AccID' + '&fkrecordID=' + '@Model.Item2[i].fkrecordID'" class="btn
            btn-primary" id="pdf-download">Download PDF</a>

Parallel in ajax-

<script type="text/javascript">
$(function () {
    $('#pdf-download').click(function () {
        $.ajax({
            url: '/LedgerIndex/PDF/?AccID=' + '@Model.Item1.AccID' + '&fkrecordID=' + '@Model.Item2[i].fkrecordID',
            type: 'post',
        });

    });

});                        
</script>

Upvotes: 1

Views: 196

Answers (2)

Rory McCrossan
Rory McCrossan

Reputation: 337560

You don't need to use javascript to concatenate values coming from server-side code. Also, your quotes are inconsistent. Try this for the anchor link:

<a href="/LedgerIndex/PDF/[email protected]&[email protected][i].fkrecordID" 
    class="btn btn-primary" 
    id="pdf-download">
    Download PDF
</a>

You could also use the built in ActionLink HtmlHelper:

@Html.ActionLink(
    "Download PDF", 
    "PDF", 
    new { 
        AccID = Model.Item1.AccID,
        fkrecordID = Model.Item2[i].fkrecordID
    }, 
    new { 
        @class = "btn btn-primary", 
        id = "pdf-download" 
    }
);

Upvotes: 1

penaservices
penaservices

Reputation: 21

Try

$.ajax({
    url: '/LedgerIndex/PDF/',
    type: 'post',
    data: { 
        AccID: "@Model.Item1.AccID", 
        fkrecordID: "@Model.Item2[i].fkrecordID"
    }
});

Upvotes: 1

Related Questions