2017-04-25 152 views
0

我一直停留在這個問題上,在過去的幾天裏,我用我的生命,我不能工作,如何從我的下拉導航到一個外部頁面一個按鈕,在點擊這種情況下的行動鏈接。我至今:獲取價值,並用它

@Html.DropDownList("DropDown", (SelectList)ViewBag.Test) 
    @Html.ActionLink("GO", "Go") 

控制器:與他們的網頁鏈接存儲在WebLink

public ActionResult Index() 
     { 
      ViewBag.DropDown = new SelectList(Services.GetData(), "WebLink", "WebLinkName");     
      return View(); 
     } 

public IEnumerable<Data> Get() 
    { 
     var db = new conn(); 
     return db.data; 
    } 

這給了我我想要的結果,一個下拉,顯示站點名稱見我的工作下拉:

enter image description here

我在哪裏看到它顯示網絡鏈接正在存儲: enter image description here

那麼我需要在我的ActionResult?下面是空的,我不知道如何在重定向獲取網絡鏈接值

public async Task<ActionResult> Go() 
    { 
     return Redirect("");// What goes here? 
    } 
+0

當圍棋的ActionResult被稱爲? – Komal

+0

你發送參數去的ActionResult試過嗎? – Komal

+0

爲什麼你沒有的jQuery做..它會通過Jquery的 –

回答

0

,你可以用下面這樣做:

public async Task<ActionResult> Go() 
{ 
    Response.Redirect("www.google.com"); 
     return null; 
} 

沒有測試,但是,我認爲它會爲你工作

,如果你想通過jQuery來做到這一點,那麼你可以如下做到這一點:

$('[id$=GO]').on('click', function() { 
      var dropdownValue = $('[id$=dropdownList]').val(); 
      window.location.href = dropdownValue; 
     }); 

希望這種溶膠解決你的問題。

+0

最好的方法我花了一個快速速成班是您更容易做到這一點Jquery,這是做這個工作的。謝謝 – Phil3992