0

ユーザーが検索を実行できる部分ビューがあり、検索結果が選択ボックスに表示されます。私のメインビューには、選択ボタンが押された後に検索結果を表示するセクションがあります。現在、選択ボタンをクリックすると、正しい情報がメイン ビューの正しいモデルに読み込まれますが、メイン ビューは変更されません。更新をクリックすると、ページが正しく更新されます。プラグイン ビューでボタンがクリックされたときにページを自動的に更新するにはどうすればよいですか?

Index.vbhtmlメイン アプリのメイン ビュー ( ) のセクション:

@Section CUInfo

 Credit Union Name: @Model.CUInfo.CUName

 end section

プラグインのコントローラー メソッドは次のとおりです。

Function ChangeCUInfo(strCUName As String) As ActionResult
        m_hostApp.CUInfo.CUName = strCUName
        m_hostApp.blnPluginRefreshButtonPressed = True
        Return View("Index", m_hostApp)
    End Function

hostApp オブジェクトにブール値を設定しようとしましたが、メインのカミソリ ビューで true の場合はこの関数を呼び出します。

@code
     If Model.blnPluginRefreshButtonPressed = True Then


         @<script type="text/javascript">
              $(function () {
                  window.location.reload();
              });
         </script>


      End If

      Model.blnPluginRefreshButtonPressed = False
End Code

編集:

選択ボタンがクリックされたときに呼び出される JS 関数:

function loadCU(CUInfo) {
           strCU = CUInfo.split('|');
           strCUName = strCU[0];         
           $.ajax({
           type: "POST",
           url: "/CUContractNumberPlugin/ChangeCUInfo",
           data: { "strCUName": strCUName }
       });
       }

プラグイン ビューで使用されるフォーム:

@Using (Html.BeginForm("ChangeCUInfo", "CUContractNumberPlugin"))
                 @<div id="LogoSigSearch" style="height:300px;width:500px;position:relative;">



    <span style="display:inline-block;height:20px;width:166px;position:absolute;top:35px;left:5px;">Credit Union Name</span>


    <br />
     @Html.TextBox("strCUName")
    <input type="submit" name="LogoSigSearch$ctl02" value="Search" id="LogoSigSearch_ctl02" tabindex="3" style="width:60px;position:absolute;top:5px;left:352px;" />






    <input name="LogoSigSearch$ctl05" type="button" onclick="javascript:clearSearch()" value="Clear" style="position:absolute;top:35px;left:352px;width:60px;" />

    <select size="4" name="LogoSigSearch$ctl06" id="LogoSigSearch_ctl06" tabindex="5" style="height:230px;width:342px;position:absolute;top:65px;left:5px;"></select>

    <input type="button" name="SelectCU" value="Select" onclick="javascript:loadCU(LogoSigSearch_ctl06.options[LogoSigSearch_ctl06.selectedIndex].value)"  tabindex="4" style="width:60px;position:absolute;top:65px;left:352px;" />
        </div>
    End Using
4

1 に答える 1

0

両方のボタンがフォームの一部ですか? ボタンは、スクリプトにアタッチするか、アクションが関連付けられたフォームの一部にしない限り、アクションを呼び出すことはありません。

メインページの読み込み時であっても、部分ビューを使用してクエリの結果をレンダリングします。これにより、開発が簡素化されます。

jQuery イベント ハンドラー ( jQuery.on() ) を追加して、メイン ページでのボタンのクリックを監視します。または、部分ビューでボタンが返された場合は、パーシャルで on ready ハンドラーを使用して、button.click( をアタッチします。 ) イベント、ここでも jQuery を使用します。

jQuery イベント ハンドラーは、クエリの値の送信、コントローラーへのポスト、および結果の表示を処理できます。ここには古い記事がいくつかありますが、それらはまだあなたの質問に関連しており、データの送信とパーシャルのフェッチを示しています。

クライアント側のコードは、次のようになります。

 $("#your-button").click(function () {
    var fetchUrl = '@Url.Action("ActionName", "Controller")';

    $.post(fetchUrl, { searchParams: $("#your-search-box").val() })
        .success(function (data) {
          // replace the contents of the DIV with the results. 'data' 
          // here has whatever you sent back from your partial view
        })
        .error(function (data) { 
          // handle the error, use a DIV with some kind of alert message etc
        });

});

これが役立つことを願っています。

于 2012-07-06T16:01:41.487 に答える