开发者

How to add a new item to a dropdownlist in a create form in MVC 3?

I have a Form to cre开发者_运维技巧ate a new model object and persist it. That form is displayed in a lightbox or popup.

Some fields are dropdownlist showing related info that lives in another table (other model object related to the main model).

What I need to achieve is without leaving the creation form, create a new item of the related type and update the DropDownList in order to continue filling fields and finaly submit the form.

I have done this in winforms but not really sure which is the best approach in MVC 3:

  • Trigger another popup with a small form?
  • Use some kind of editable dropdownlist?
  • Place a small hidden form right next/after the DDL to allow entering the info to create an item in DDL (and to DB also)?

What do you thing is the best option?

Thanks!


There is no editable dropdown list in HTML. There are some toolkits that simulate it, but in general these are clumbsy and really complex. It's a lot easier to stick with basic controls.

You would proably do best to have a small + sign next to the field, and then popup an editing field that inserts the element into the combobox and sends it to the controller via ajax to add to the database.


An alternative to a second pop up is having a toggle add button. When toggled, then show a small area where you can enter the name. Using ajax, save the name, and then refresh your dropdown. This works well if you only have a few attributes to fill in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜