2011-09-26 36 views
1

我有一個DDL,在其更改我加載部分視圖_GetX。現在我正在使用它像這樣如何加載在mvc3按鈕單擊部分視圖

@Html.DropDownListFor(model => model.XId, Model.XList, "Select", new { GetUrl = Url.Action("GetX", "Route") }) 

我需要單擊按鈕加載此局部視圖。我該怎麼做呢?

+0

您希望在DDL改變加載的局部視圖或點擊一些其他的按鈕時? –

+0

當點擊其他buton時 – TJK

回答

0

假設你GetX控制器動作已經返回局部視圖:

$(function() { 
    $('#someButton').click(function() { 
     // get the DDL. It would be better to add an id to it 
     var ddl = $('#XId'); 

     // get the url from the ddl 
     var url = ddl.attr('GetUrl'); 

     // get the selected value of the ddl to send it to the action as well 
     var selectedValue = ddl.val(); 

     // send an AJAX request to the controller action passing the currently 
     // selected value of the DDL and store the results into 
     // some content placeholder   
     $('#somePlaceholder').load(url, { value: selectedValue }); 

     return false; 
    }); 
}); 
相關問題