“添加新项目" asp.net mvc下拉列表中的按钮 [英] "Add new item" button within asp.net mvc dropdown list

查看:103
本文介绍了“添加新项目" asp.net mvc下拉列表中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我要在asp.net mvc应用程序中的下拉列表中添加项目,方法是单击同一页面上的链接,然后将项目添加到该下拉列表所绑定的数据库表中.

Currently, I am adding items to a dropdown list in my asp.net mvc application by clicking on a link on the same page and adding an item to the database table that the dropdown list is bound to.

我希望此链接"成为下拉列表中的一项,以便列表项看起来像

I want this "link" to be an item WITHIN the drop down list so the list items will look something like

  • 第1项
  • 第2项
  • 第3项
  • 添加新项

,当用户选择添加新项"时,将弹出一个对话框,用户可以在其中输入要添加到列表中的内容.

and when the user selects "add new item", a dialog will pop up where the user can enter something to add to the list.

我一直在互联网上寻找解决方案,但找不到任何东西,有人能指出正确的方向吗?

I've been searching all over the internet for a solution to this and I cannot find anything, can anyone point me in the right direction?

谢谢!

推荐答案

您应该处理下拉列表的事件.然后,调用对话框,用户可以在下拉菜单中输入一些值.您可以使用JQuery来实现以下目的:

You should handle the event of your dropdownlist.. Then, call the dialog where the user can input some value in your dropdown. You can achieve something like this by using JQuery:

$('#dropdownId').change(function (){
    var drpValue = $('#dropdownId').val();
    if(drpValue == "Add New Item"){
        //call method or show your dialog here;
    }
});

您仍然可以通过两种方法将其直接添加到下拉菜单中:

There are still two ways you can manage to add it directly to your dropdown:

  1. 回发
  2. 使用Ajax

这篇关于“添加新项目" asp.net mvc下拉列表中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆