@model IEnumerable<SE01.Models.BMFixture>
@{
ViewBag.Title = "Fixtures";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Fixtures</h2>
<table id="bmfixtures" class="table table-bordered table-hover">
<thead>
<tr>
<th>Market</th>
<th>Market</th>
<th>Selection</th>
<th>Bookmaker</th>
<th>Odds</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
@section scripts
{
<script>
$(document).ready(function() {
$("#bmfixtures").DataTable({
ajax: {
url: "/Api/BMFixtures",
datasrc: ""
},
columns: [
{
data: "marketname",
render: function(data, type, bmfixture) {
return "<a href='/bmfixtures/edit/" + bmfixture.Id + "'>" + bmfixture.marketname + "</a>";
}
},
{
data: "marketname"
},
{
data: "selectionname"
},
{
data: "bookmakername"
},
{
data: "bookmakerodds"
},
{
data: "id",
render: function(data) {
return "<button class='btn-link js-delete' data-bmfixture-id=" + data + ">Delete</button>";
}
}
]
});
$("#bmfixtures").on("click", " .js-delete", function() {
var button = $(this);
if (confirm("Are you sure you want to delete this fixture?")) {
$.ajax({
url: "/api/bmfixtures/" + button.attr("data-bmfixture-id"),
method: "DELETE",
success: function() {
button.parents("tr").remove();
}
});
}
});
});
</script>
}
안녕 내가 간단한 데모를 시도하고 그러나 나는 당신의 데이터를 사용하지 않는, 잘 작동 것으로 보인다, JSON 형식의 문제 일 수 있습니다. 내가 다르게 한 만 가지 작은 따옴표를 사용하고 완전히 URL을 자격이 있습니다 - 그래서 (예 :
url: "http://localhost:60241/api/bmfixtures"
)
예를하려고 (등 링크에서 데이터를 변경 한 단지 그래서 당신은 아이디어를 얻을) :
@{
ViewBag.Title = "Fixtures";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Fixtures</h2>
<table id="bmfixtures" class="table table-bordered table-hover">
<thead>
<tr>
<th></th>
<th>id</th>
<th>type</th>
<th>text</th>
<th></th>
</tr>
</thead>
<tbody></tbody>
</table>
@section scripts
{
<script>
$("#bmfixtures").DataTable({
ajax: {
// Replace below line with: url: "http://localhost:60241/api/bmfixtures", (in your version)
url: "http://api.scb.se/OV0104/v1/doris/en/ssd",
dataSrc: ''
},
columns: [
{
data: 'id',
render: function (data, type, bmfixture) {
return "<a href='/bmfixtures/edit/" + bmfixture.id + "'>" + bmfixture.id + "</a>";
}
},
{ data: 'id' },
{ data: 'type' },
{ data: 'text' },
{
data: 'id',
render: function (data) {
return "<button class='btn-link js-delete' data-bmfixture-id=" + data + ">Delete</button>";
}
}
]
});
</script>
}
감사합니다 VERy much indeed @James 나는 밤늦게까지 일했고 깨끗한 시작 (또 다른 데이터 문제도 있었음)을 위해 바닥에서부터 시스템을 완전히 재건했다. 그리고 문제는 여전히 지속되었다 ... 내가 시작하기 전까지는 ... 한 칼럼으로 시작하는 칼럼을 가지고 주변을 점진적으로 구축하십시오. 낮은 수치이며, href를 삭제하면 작동합니다. 재미있는 것은 당신이 말했을 때 작은 따옴표로 시도했지만 작동하지 않았습니다. 적어도 나는 그것이 작동하는 것을 안다. 그리고 그것이 문제가있는 곳이다. 나는 더 실험 할 것이다. 당신은 스타입니다! – user6063812
이것은 James의 문제점을 보여주고 있습니다 - 나는 변수를 편집 href에 통합하는 법을 모르겠습니다 - 참조 http://stackoverflow.com/questions/39374866/dynamic-link-in-datatables-column- returning-undefined – user6063812
제임스 감사합니다 - 당신의 답변 - 이드가 아닌 이드 (소문자) 여야합니다. – user6063812