@MrChiefは醜いハックについて上記の考えを持っていました...私はそれをまとめました。これが私がこれを行うために使用したメインコードです。確かに、ネットワークに接続される前に ajax 呼び出しをハイジャックします。重要なのは、送信される URL を変更することです。これは、グリッドが HttpContext.Request.Path からその URL を取得するためです。アンカー要素の onclick にプラグインします。
これをメインの common.js に配置し、データが送信される直前に発生する ajaxSend イベントをキャプチャする関数を添付するだけです。
// Used to hijack the sending of all AJAX calls. Before it sends the call to the server, it checks to see if the
// active element (the element that prompted the call) is marked with a given class. If so, then it will perform
// the given operation.
$(document).ajaxSend(function (event, jqXHR, ajaxOptions) {
var activeElement = document.activeElement;
if ($(activeElement).attr('redosorturl') != null) {
// If this is a sort anchor link from a grid that needs to have the sort link redone, do it here.
// the code is in the eipGrip.js file.
if ($(activeElement).attr('redosorturl').toString() == 'redoSortURL') {
var newURL = RedoGridSortURL(activeElement, ajaxOptions.url.toString());
ajaxOptions.url = newURL.toString();
}
}
return false;
});
ページをレンダリングするときに、間違った URL を含む列ヘッダーのタグを「redosorturl」という名前のクラスでマークしたので、ajax 呼び出しを乗っ取ったときに、この要素で操作を行う必要があることがわかります。正しい URL を提供するカスタム関数を使用すると、ajaxOptions.url がその新しい URL で書き換えられます。
DOM をトラバースしてグリッド情報を取得できるように、activeElement をその書き換え関数に渡す必要があります。グリッド情報には、URL に使用する ID やその他の情報と共に使用されるコントローラーやアクション メソッドなどのデータを配置します。 . 同様に、現在の URL 文字列を渡します。これは、グリッドが URL の末尾にトークンを挿入し、それを解析して新しい URL に配置するためです。