简体   繁体   English

从下拉列表中动态添加对象到列表

[英]Dynamically add objects to list from dropdown

I'm going to try and put this in the simplest terms and hopefully someone can help me.我将尝试用最简单的术语来表达它,希望有人可以帮助我。 I'm new to MVC and i'm trying to learn the ropes.我是 MVC 的新手,我正在尝试学习技巧。

I have an dropdown that is populated with tenant objects.我有一个填充了租户对象的下拉列表。

I want a user to be able to select a tenant in the drop down, and have that tenant added to a list (Enumerable of Tenant objects) and displayed below the dropdown in a section called "Added Tenants" while also removing the selected tenant from the dropdown.我希望用户能够在下拉列表中选择一个租户,并将该租户添加到列表(租户对象的枚举)中并显示在名为“添加的租户”部分的下拉列表下方,同时还从下拉菜单。

I don't want these tenants added to the database until later because this is a form creating a lease, and i want them to finish filling out the rest of the lease and create it all at once.我不希望这些租户稍后添加到数据库中,因为这是一个创建租约的表单,我希望他们完成租约的其余部分并一次性创建所有租约。

I'm hoping someone can help me or at least point me in the right direction.我希望有人可以帮助我,或者至少为我指明正确的方向。 Yes i have done searches but haven't found anything yet that will help me or that i understood.是的,我已经进行了搜索,但还没有找到任何可以帮助我或我理解的东西。

Edit: The list can be of object, just an id, or even a select list.编辑:列表可以是对象,只是一个 id,甚至是一个选择列表。 The end game is to use that list to add them to the collection which is a 1 to many relationship.最后的游戏是使用该列表将它们添加到集合中,这是一对多的关系。 That list will also be used to populate partial views with the tenant information, kind of like how the tags work in stack overflow.该列表还将用于使用租户信息填充部分视图,有点像标签在堆栈溢出中的工作方式。

While it's not clear what the "list" is that you want added to (ie a UL or a form select list), but this solution is going to be done in javascript, not ASP.虽然不清楚您想要添加的“列表”是什么(即 UL 或表单选择列表),但此解决方案将在 javascript 中完成,而不是 ASP。

Try doing a few searches on SO.尝试对 SO 进行一些搜索。 Such as:如:

jQuery moving MultiSelect values to another MultiSelect jQuery 将 MultiSelect 值移动到另一个 MultiSelect

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM