【问题标题】:Fill a Droplist.for by clicking on another Droplist.for通过单击另一个 Droplist.for 填充 Droplist.for
【发布时间】:2019-05-15 23:55:48
【问题描述】:

当我从另一个 DropList.For 中选择一个项目时,我正在尝试填充一个 DropList.For。到目前为止,这是我的代码:

@Html.LabelFor(m => m.Cliente, new { @class = "control-label col-md-2" })
                            @Html.DropDownListFor(model => model.SelectedCategoryId,
                                    new SelectList(Model.Cliente, "CategoryId", "CategoryName"), "- Please Select -")
                            @Html.ValidationMessageFor(x => x.Cliente, null, new { @class = "label label-danger" })

                            @Html.LabelFor(m => m.Tipo_servicio, new { @class = "control-label col-md-2" })
                            @Html.DropDownListFor(model => model.SelectedCategoryId,
                                    new SelectList(Model.Tipo_servicio, "CategoryId", "CategoryName"), "- Please Select -")
                            @Html.ValidationMessageFor(x => x.Tipo_servicio, null, new { @class = "label label-danger" })

所以我将它放在我的视图中并用 EntityFramework 填充它

【问题讨论】:

  • 根据您尝试填充的数据集的大小,我会说只需加载第二个下拉列表的数据并在第一个下拉列表的值更改时过滤值。
  • 我明白了,我会带着 ViewBag 回来吗?
  • 在您的 Controller.cs 文件中,在为您正在处理的视图返回 ActionResult 的方法上传递一个模型,例如 return View(model); 并使用您需要的所有数据填充该模型.
  • 那不会让我刷新我的视野并再次为所有东西充电?
  • 我的意思是你在最初加载视图时传递了整个数据。

标签: c# html model-view-controller


【解决方案1】:

您可以使用“onChange”事件,您可以查看以下链接。

  1. 对多个下拉菜单使用相同的方法: same method for multiple ddl

  2. 不同Dropdown的不同方法: enter link description here

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    • 2021-10-27
    相关资源
    最近更新 更多