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>
Try
$.ajax({
url: '/LedgerIndex/PDF/',
type: 'post',
data: {
AccID: "@Model.Item1.AccID",
fkrecordID: "@Model.Item2[i].fkrecordID"
}
});
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/?AccID=@Model.Item1.AccID&fkrecordID=@Model.Item2[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"
}
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.