私は他の多くの同様の質問を見てきましたが、目標がまったく同じものは見つかりませんでした。ASP.NET MVC4 の ADO.NET エンティティ モデルを使用して、データベースからデータ テーブルの行を取得しています。特定の行のリンクをクリックして、そのリンクをクリックすると、完全に異なるデータベーステーブルからの行の完全に異なるデータテーブルに移動できますが、クリックした行のリンクに関連付けられています。クリックしたリンクを表示したい新しいデータテーブルにバインドするデータは、各行の非表示の列にあります。full[]配列のビューモデルに対応するインデックスを介して、「mRender」関数からそのデータにアクセスできることがわかりました。
私は MVC と jQuery の両方に非常に精通しているので、私のコードを読むときはご容赦ください。
これが私の見解です:
@using System.Web.Optimization
@{
ViewBag.Title = "ShowPeople";
}
<h2>ShowPeople</h2>
<div id="example_wrapper" class="dataTables_wrapper form-inline" role="grid">
<table border="0" class="table table-striped table-bordered dataTable" id="people" aria-describedby="example_info">
<thead>
<tr role="row">
<th class="sorting" role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">Header1</th>
<th class="sorting" role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">Header2</th>
<th class="sorting" role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">Header3</th>
<th class="sorting" role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">Header4</th>
<th class="sorting" role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">Header5</th>
<th class="sorting" role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">Header6</th>
<th class="sorting" role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">Header7</th>
<th class="sorting" role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">Header8</th>
<th class="sorting" role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">Header9</th>
<th class="sorting" role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">Header10</th>
<th role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">ID_PART1</th>
<th role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">ID_PART2</th>
<th role="columnheader" tabindex="0" rowspan="1" colspan="1" aria-controls="example">LINKS</th>
</tr>
</thead>
<tbody role="alert" aria-live="polite" aria-relevant="all"></tbody>
</table>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#people').dataTable({
"bServerSide": true,
"sAjaxSource": "DataAjaxHandler",
"bProcessing": true,
"sPaginationType": "full_numbers",
"aoColumns": [
{ "sName": "data1" },
{ "sName": "data2" },
{ "sName": "data3" },
{ "sName": "data4" },
{ "sName": "data5" },
{ "sName": "data6" },
{ "sName": "data7" },
{ "sName": "data8" },
{ "sName": "data9" },
{ "sName": "data10" },
{
"sName": "ID_ONE",
"bVisible": false,
"bSearchable": false,
"bSortable": false,
"mData": null
},
{
"sName": "ID_TWO",
"bVisible": false,
"bSearchable": false,
"bSortable": false,
"mData": null
},
{
"sName": "Links",
"bSortable": false,
"bSearchable": false,
"mData": null,
"mRender": function (data, type, full) {
var urlBase = "@Url.Action("ShowData", "Data")";
return "<a href='" + urlBase + "/?id1=" + full[10] + "&id2=" + full[11] + "'>Events</a>";
}
}
]
});
});
</script>
これが私のコントローラーです:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Web_UI.Models;
namespace Web_UI.Controllers
{
public class DataController : Controller
{
//
// GET: /Reports/
public ActionResult ShowData()
{
return View();
}
public ActionResult DataAjaxHandler(jQueryDataTableParamModel param)
{
//How can I get those IDs?
}
}
}
私が把握しようとしているのは、非表示の ID 列からコントローラーの ajaxhandler アクション メソッドにデータを取得する方法があるかどうかです。linq を使用してデータベースから必要なデータを取得する方法は知っていますが、取得するためにリンクをクリックした特定の行の ID 列からのデータが必要です。これを達成する方法はありますか?
私がすでに読んだ質問の多くは、「fnServerParams」関数を使用してデータをプッシュすることに関するものですが、それがどのように機能するかをよく理解していません。私が見たすべての例は非常に静的に見えます (常に同じデータをプッシュするため) )。リンクの URL を提供するコードは、現時点では何も実行していません。これは、いくつかの非表示の列からデータにアクセスする方法を理解するための演習に過ぎないためです。編集:リンク URL はどこにも行かないと言いましたが、full[10] と full[11] が正しい値を取得していないことを意味するつもりはありませんでした。コードが生成する URL を確認したところ、実際に各行の正しい ID 番号を取得しています。コントローラーで使用するためにそれらをサーバーに戻す方法がわかりません。
助けてくれてありがとう。