I am trying to pass the @Model.Id from my razor view to the javascript so that I can pass it to the dataTables ajax url but I cant manage to get the value to the javascript file. Even just a point in the right direction would help at this point
Here is the View:
@model GTravel.Domain.Package
@{
var title = Model.Name;
}
//boring html code
@section Scripts{
<script src="~/js/packageCity.js" data-packageId="@Model.Id"></script>
}
And a snippet of the js:
var dataTable;
var url;
$(document).ready(function () {
url = "/admin/packageCity/GetAll/" + packageId.toString();
loadDataTable();
});
function loadDataTable() {
dataTable = $('#tblData').DataTable({
"ajax": {
"url": url,
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "city", "width": "10%" },
//more code etc