[英]how to get the selected item from html dropdown list and pass it to another controller in mvc c#
我正在將值添加到我的Html.Dropdownlist
如下所示。
<div class="col-md-4">
<h2 style="color: #2f6207">dfdfDestination</h2>
@Html.DropDownList("accountID", new SelectList(ViewBag.Destination, "regCde", "Destination"))
</div>
@Html.ActionLink("SEARCH NOW", "MscHome")
它工作正常。 現在我想獲取用戶選擇的值,並在單擊按鈕時將其傳遞給另一個控制器( action link
)
public ActionResult MscHome(string accountID)
{
ViewBag.requested = Session["search"];
Thread.Sleep(10000);
return View();
}
但這顯示為null
值。
實現此目標的一種方法是,首先針對同一控制器,從下拉列表中獲取值,然后重定向至第二個控制器,將值作為參數傳遞。 使用RedirectToAction和TempData或將值設置為調用中的參數。
如果僅返回另一個控制器使用的視圖,則在某些情況下可以這樣做。 但是,如果需要使用位於其他控制器中的代碼初始化視圖,則將打開一個空視圖。 這就是RedirectToAction所防止的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.