我想实现一个已经在我同事的 asp.net 应用程序中编写的功能。我想在 asp.net mvc 中实现相同的逻辑 但我不知道如何在 Controller 的操作中获取下拉列表控件的 ID 他所做的是通过调用如下所示的函数来填充下拉列表
Global.BindRigionByApplicationAccess(drpRegion,
ConfigurationManager.AppSettings["ApplicationId"],
ref ErrorMessage);
这里 'drpRegion' 是 dropdownlist 的 id,在 asp.net 中只需简单调用该函数即可加载数据。
我在 asp.net mvc 中做了以下代码
在 View 中
@Html.DropDownList("REGION_CODE", (SelectList)ViewBag.gpregions)
最佳答案
您无法在 Controller 操作中访问下拉列表。请了解有关 MVC 模式的更多信息:http://www.microsoftvirtualacademy.com/training-courses/introduction-to-asp-net-mvc http://www.asp.net/mvc/overview/getting-started/introduction/getting-started
您需要创建一个要绑定(bind)的数据列表,并通过返回将数据传递给 View :
return View(myDataViewModel);
之后,您可以使用该数据创建下拉列表。
另请参阅:http://www.asp.net/mvc/overview/views/dynamic-v-strongly-typed-views
关于c# - 如何在 Controller 的操作中访问下拉列表控件 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30341171/