ASP.Net MVC多个下拉菜单,单列表,仅允许唯一选择 [英] ASP.Net MVC Multiple Drop Downs, Single List, Only Allow Unique Selections
问题描述
我正在创建一个ASP.Net MVC 4网站,其中有一个控制器创建操作。
I am creating an ASP.Net MVC 4 site where I have a controller with a create action.
创建操作提供了一个视图,其中包含几个下拉列表我想从我的数据库绑定到单个实体列表。
The Create action provides a View with several dropdowns each of which I want to bind to a single list of entities from my database.
但是,我想确保每个下拉菜单中的选择是唯一的。
However, I want to ensure that the selections in each drop down are unique.
关于这样做?每次进行选择时,我需要对服务器进行一些AJAX回发,以便以某种方式更新其他下拉菜单中的可用选项?还是有一个简单的方法?
How would I go about doing this? Do I need to do some sort of AJAX postback to the server each time a selection is made to somehow update the available options on each of the other drop downs? Or is there a simpler way?
非常感谢,
Martyn Jones。
Martyn Jones.
推荐答案
在您的模型中,您可以为每个下拉菜单单个Id字段。
如下
In your model you can have individual Id fields for each Dropdown. something as below
<%: Html.DropDownListFor(model => model.DropwdownId1,Model.DropdownEntities) %>
<%: Html.DropDownListFor(model => model.DropwdownId2,Model.DropdownEntities) %>
<%: Html.DropDownListFor(model => model.DropwdownId3,Model.DropdownEntities) %>
其中 Dropdownentities 只会从数据库返回实体。
where Dropdownentities will just return entities from database.
您将能够看到Post Action中每个下拉菜单的选定值。
DropwdownId1,DropwdownId2
you shall be able to see selected values for each dropdown in Post Action. DropwdownId1 , DropwdownId2
这篇关于ASP.Net MVC多个下拉菜单,单列表,仅允许唯一选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!