[英]how to get the selected item from dropdown in MVC
This is my code: 这是我的代码:
@Html.DropDownList("Locate", new List<SelectListItem>
{
new SelectListItem {Text = "Luxor", Value="1"},
new SelectListItem {Text = "Abu Simbel Airport", Value="2"},
new SelectListItem {Text = "Other", Value="3"}
},"Select Location")
what I need is, when user select a list item, how to pass the selected item to controller. 我需要的是,当用户选择一个列表项时,如何将所选项目传递给控制器。 because data load is change according to selected list item.like below in controller.
因为数据加载根据选择的列表项而变化,例如控制器中的以下内容。
if (Value == "1")
{
return View(cp);
}
else
{
return View(cp1);
}
The easiest way to do achieve this is to POST data to server, where you send entire form content, along with your drop down list selection. 实现此目的的最简单方法是将数据POST到服务器,在此您发送整个表单内容以及下拉列表选择。 To achieve this, just add a submit button.
为此,只需添加一个提交按钮。 Please note that drop down list may only send simple data types.
请注意,下拉列表可能仅发送简单的数据类型。 In order to obtain this value after the POST, you need to adjust your controller like below:
为了在POST之后获得此值,您需要像下面那样调整控制器:
[HttpPost]
public void Mycontroller(string Locate)
{//do something with data}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.