2013-03-19 14 views

回答

7

你不能這樣做,因爲Html.Action幫手呈現在服務器上,而下拉選擇可以在客戶機上更改。一種可能性是使用AJAX調用。所以基本上你可以訂閱下拉菜單中的.change()事件,並向某個控制器動作發送一個AJAX調用,該動作將返回一個局部視圖並更新DOM。通過放置在容器中這個

開始:

<div id="container"> 
    @Html.Action("FirmPassForum", "Conference", new { eventId = 69 }) 
</div> 

然後:

<script type="text/javascript"> 
    $(function() { 
     $('#id-of-your-dropdown').change(function() { 
      var eventId = $(this).val(); 
      $.ajax({ 
       url: '@Url.Action("FirmPassForum", "Conference")', 
       type: 'GET', 
       data: { eventId: eventId }, 
       cache: false, 
       success: function(result) { 
        $('#container').html(result); 
       } 
      }); 
     }); 
    }); 
</script> 

FR這工作你FirmPassForum行動應該[ChildActionOnly]屬性來裝飾:

public ActionResult FirmPassForum(int eventId) 
{ 
    MyViewModel model = ... 
    return PartialView(model); 
} 
0

你也可以用這個

`//var url = '@Url.Action("ActionName", "Controller")'; 

$.post("/Controller/ActionName?para1=" + data, function (result) { 
    $("#" + data).html(result); 
    ............. Your code 
});` 
相關問題