如何填充基于MVC中的另一个4选择DropDownList控件值一个DropDownList? [英] how to populate a dropdownlist based on another dropdownlist selected value in mvc 4?

查看:186
本文介绍了如何填充基于MVC中的另一个4选择DropDownList控件值一个DropDownList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了两个下拉列表。关于选择从第一个下拉列表值第二个下拉列表应填写这是我查看code

I have created two Drop Down List. On selecting a value from first dropdown list second dropdown list should be filled this is my code in View

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    @Html.DropDownList("Id", ViewData["Id"] as List<SelectListItem>, new { })
    <button type="submit">next</button>
} 
@Html.DropDownList("Id", ViewData["Id1"] as List<SelectListItem>)

当我点击下一步按钮第二个下拉是越来越填充。同样的事情,我想,当我从第一个列表中的特定项目的事情。我不想使用jQuery有什么办法呢?
或者是有什么办法我怎么能产生回发时,我从第一个列表值?

When I click on next button second dropdown is getting populated. Same thing I want to do when I select a particular item from first list. I don't want to use jquery is there any way to do? Or is there any way how I can generate postback when I select value from first list?

推荐答案

我觉得你可以把第一个下拉表单内,包括改变属性这个下拉菜单:

I think you can put the first dropdown inside a form and include the change attribute to this dropdown:

@{ Html.BeginForm("Action", "Controller", FormMethod.Post, new { enctype = "multipart/form-data" }); }

    @Html.DropDownList("Id", ViewData["Id"] as List<SelectListItem>, new { onchange = "this.form.submit();" })

@{ Html.EndForm(); }

然后,控制器,你应该包括一些code来填充第二个下拉。

Then, in the controller, you should include some code to populate the second dropdown.

这篇关于如何填充基于MVC中的另一个4选择DropDownList控件值一个DropDownList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆