简体   繁体   English

如何通过另一个下拉列表中的操作填充下拉列表?

[英]How to populate a dropdownlist by an action from another drop down list?

I'm working with MVC 4.0 and I'd need a page with 3 drop downlists and a table. 我正在使用MVC 4.0,并且需要一个包含3个下拉列表和一个表的页面。

When an item is selected from DDL1 (eg Users) then DDL2 (eg Accounts) is populated. 当从DDL1(例如,用户)中选择一个项目时,将填充DDL2(例如,帐户)。 When an item is selected from DDL2 (Accounts) then DDL3 (eg Cards) is populated. 当从DDL2(帐户)中选择一个项目时,将填充DDL3(例如卡)。 When an item is selected from DDL3 then the table has to display a list of objects eg Transactions (with Amount, etc). 当从DDL3中选择一个项目时,表格必须显示一个对象列表,例如,交易(带有金额等)。

So I created a TransactionManagementController and created an Index Action which loads the Users and displays them initially. 因此,我创建了一个TransactionManagementController并创建了一个Index Action,该Action加载用户并最初显示它们。

 public ActionResult Index()
        {
            var vm = new VmTransactionManagement
                {
                    Users = db.Users.ToList()
                };

            return View(vm);
        }

<th>User:</th>
        <td>@Html.DropDownListFor(m => m.SelectedUser,
                                  Model.UsersSelectList,
                                  "-- Select One --")</td>

Also, I created a view model for this controller: VmTransactionManagement which contains some other objects needed. 另外,我为此控制器创建了一个视图模型:VmTransactionManagement,其中包含一些其他需要的对象。

So, now how would I code so that when DDL1 is selected (userId is passed), then DDL2 gets populated? 那么,现在我该如何编码,以便在选择DDL1(传递了userId)之后填充DDL2?

Should I be creating a new action/view and calling it by Ajax? 我应该创建一个新的动作/视图并由Ajax调用吗?

If I create a new Action, then I'll have to create a new View which changes the previously selected values. 如果我创建一个新的动作,则必须创建一个新的视图来更改以前选择的值。

When I need to cascade drop down lists, I will use jQuery $.load and render the PartialView. 当我需要级联下拉列表时,我将使用jQuery $.load并渲染PartialView。 An example using technique is at https://stackoverflow.com/a/1721623/1015010 使用技术的示例位于https://stackoverflow.com/a/1721623/1015010

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从另一个下拉列表填充一个下拉列表 - How to populate a drop down list from another drop down list 如何从SQL填充GridView下拉列表选项? - How to populate a GridView drop-down list choices from SQL? 从另一个下拉列表填充一个下拉列表 - populate a dropdownlist from another dropdownlist 从另一个DropDownList填充DropDownList - Populate DropDownList from another DropDownList 如何根据另一个下拉列表中的选项填充下拉列表? - How do I populate a dropdownlist based on a selection from another dropdownlist? Asp.Net如何从另一个下拉列表填充下拉列表 - Asp.Net How to populate dropdownlist from another dropdownlist 如何从Web服务列表中填充dropDownList <string> - How to populate a dropDownList from a webservice list<string> 根据MVC 4中的另一个下拉列表选择值填充下拉列表 - Populate a drop down list based on another drop down list selected value in MVC 4 根据对其他下拉列表中值的选择,填充一个下拉列表值 - Populate one dropdownlist value based on the selection of the value on other drop down list 有没有办法从asp.net MVC的另一个下拉列表中的先前选择中更改@ Html.DropDownList的值 - Is there a way to change the values of a @Html.DropDownList from a previous selection in another drop down list in asp.net MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM