2012-10-23 70 views
2

我有一個共同的佈局頁面的意見。此佈局頁面包含一個下拉列表,其中顯示可用日期的列表。我想要的是重新加載這個頁面只改變了數據參數。控制器,動作和其他參數應該以某種方式從當前的請求上下文中獲取。如何刷新頁面上的下拉列表值更改?

如果我想這樣做手工上的每個觀點,我會說這將是等於

@Html.ActionLink(
    "",           
    "I need to have current action name here", 
    new { date = "The Value of the chosen SelectListItem" }); 

我怎樣才能做到這一點?或者有什麼不同的方法?

回答

2

關於當前操作的信息,請RequestContext,你可以直接訪問它:

@Url.Action(ViewContext.RequestContext.RouteData.Values["action"], 
     new { date = "The Value of the chosen SelectListItem" }); 

在你的情況我想補充的網址到選項數據屬性,然後使用它與jQuery:

$('select#yourid').change(function() { 
    document.location.href = $(this).find('option:selected').data('url')); 
});​ 

如何獲取在下拉列表改變數據屬性可以在這個FIDDLE可以看出。

+0

不好意思,但是如何讓瀏覽器去下拉列表中的這個鏈接值的變化呢? – horgh

+0

更新了我的答案。如果您需要渲染部分的幫助,請告訴我。我目前沒有Visual Studio在手.. –

+0

非常感謝!我非常感謝你的幫助 – horgh

-2

HTML:

<select id="mySelect" name="list" size="1"> 
    <option value="1">Option 1</option> 
    <option value="2">Option 2</option> 
</select> 
<span id="tag"></span> 

的Javascript:

//cache the select and span elements var mySelect = 
document.getElementById("mySelect"), 
tag = document.getElementById("tag"); //when it changes 
mySelect.onchange = function() { 
//change the tag innerHTML checking the selected value of the select 
tag.innerHTML = mySelect.value === "1" ? "some text" : "some other text"; } 

這是一個例子。如果你婉加載其他頁面級調用另一個JS功能,或AJAX控件

相關問題