【发布时间】: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