2017-12-13 11 views
0

私は次のビューBoard.cshtmlを持っています。ここでは、DropDownListForというイベントに基づいて部分ビューMessagesBoard.cshtmlをレンダリングします。コントローラメソッドに値が渡されない

Boards.cshtml

<script> 
    $(function() { 
     debugger 
     $("#selected_listBulletinBoardsMessages").change(function (e) { 
      alert($(this).val()); 
      var val = $(this).val(); 
      $("#updateBulletMessagesView").load("UpdateBoardMessages/", { listBulletinBoardsMessages: val }); 
     }); 
    }); 
</script> 
<div> 
    @Html.DropDownListFor(model => model.listBulletinBoardsMessages, Model.listBulletinBoardsMessages.Select(b => new SelectListItem() { Value = b.Department, Text = b.Department }), "All Departments", 
      new { @class = "form-control", 
       id = "selected_listBulletinBoardsMessages" 
     }) 
</div> 

<div id="updateBulletMessagesView"> 
    @Html.Partial("MessagesBoard") 
</div> 

コントローラ方法:UpdateBoardMessagesは、jQueryのスクリプトから送信されたvalの値を持っていません。

public ActionResult UpdateBoardMessages(string val) 
     { 
      val = val; //NULL?? 
      .. 
      return PartialView("MessagesBoard.cshtml"); 
     } 

私は間違っていますか?

+0

あなたのコントローラーアクションは呼ばれていますか? –

+0

変数をvalではなくlistBulletinBoardsMessagesとして渡しています。 – Fran

+0

@エーザンサジャッドはい。 – ot0

答えて

0

あなたが実際に代わりに魔法の文字列を使用しての正しいURLを生成し、その後、あなたのようなJavaScriptの何かの文字列conctenationによりクエリ文字列パラメータを追加することができUrl.Actionを使用する必要があります。

$("#updateBulletMessagesView").load('@Url.Action("UpdateBoardMessages","ControllerName")'+'?val='+val; 

・ホープ、このことができます。

+2

エラー '&val =' + val; 'は' '?val =' + val; ''でなければなりません – Dans

+0

実際にはコントローラの動作が壊れません。 – ot0

+0

ありがとう@dansはそれを修正しました –

関連する問題