Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 根据对DropDownList 1的选择自动选择DropDownList 2中的值_Asp.net Mvc_Asp.net Mvc 3_Razor - Fatal编程技术网

Asp.net mvc 根据对DropDownList 1的选择自动选择DropDownList 2中的值

Asp.net mvc 根据对DropDownList 1的选择自动选择DropDownList 2中的值,asp.net-mvc,asp.net-mvc-3,razor,Asp.net Mvc,Asp.net Mvc 3,Razor,我是ASP.NETMVC3.0的新手。我正在尝试根据用户在DropDownList 1中选择的值自动选择DropDownList 2中的值 我如何实现这一点 更多详细信息:DropDownList1显示城市列表,如果用户选择City1,则DropDownList2自动选择LakePopular(其中DropDownList2显示城市的独特之处) 到目前为止,我能够在控制器中使用ViewBag和SelectList显示dropdownlist 欢迎您提供任何建议您需要处理DropDownList的

我是ASP.NETMVC3.0的新手。我正在尝试根据用户在DropDownList 1中选择的值自动选择DropDownList 2中的值

我如何实现这一点

更多详细信息:DropDownList1显示城市列表,如果用户选择City1,则DropDownList2自动选择LakePopular(其中DropDownList2显示城市的独特之处)

到目前为止,我能够在控制器中使用ViewBag和SelectList显示dropdownlist


欢迎您提供任何建议

您需要处理DropDownList的OnSelectedIndexChanged事件1。这是在服务器端执行的,可以比较该值,然后设置DropDownList2

示例.aspx:

<asp:DropDownList ID="DropDownList1" OnSelectedIndexChanged="ddl1_Changed">
<asp:ListItem Value="City1">City1</asp:ListItem>
<asp:ListItem Value="City2">City2</asp:ListItem>
</asp:DropDownList>
//
<asp:DropDownList ID="DropDownList2">
<asp:ListItem Value="City1">LakePopular</asp:ListItem>
<asp:ListItem Value="City2">Desert</asp:ListItem>
</asp:DropDownList>

当然,您可以使用javascript在客户端执行此操作,但这种方式更快、更简单。如果您不喜欢页面刷新,请将其全部放在AJAX更新面板中。

我正在寻找MVC 3.0中的一些示例,razor engine代替了aspx。
protected void ddl1_changed(object sender, EventArgs e)
{
DropDownList2.SelectedValue = DropDownList1.SelectedValue;
}