如何从中选择项目后从下拉列表中删除项目 [英] how to remove an item from the drop down list once an item has been selected from it in

查看:59
本文介绍了如何从中选择项目后从下拉列表中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在asp.net mvc4中从中选择了一个项目,我怎么能从下拉列表中删除一个项目?看到流程中有会议列表和开发人员列表,您现在必须选择任何会议并向其添加开发人员,但我不能将开发人员两次添加到会议中吗?我想知道您是否可以这样做或者是否有验证?这是我的控制器:



公共类ConferenceAttendantController:Controller

{

private PrjctMngmt2Entities db = new PrjctMngmt2Entities( );



//

// GET:/ ConferenceAttendants /



public ViewResult Index()

{

var ConferenceAttendants = db.ConferenceAttendants.Include(Conference)。Include(Developer);

返回查看(ConferenceAttendants.ToList());

}



//

// GET :/ ConferenceAttendants / Create



public ActionResult Create()

{

ViewBag.ConferenceID = new SelectList( db.Conferences.OrderBy(d => d.Name),ConferenceID,Name);

ViewBag.DeveloperID = new SelectList(db.Developers.Select(d => new) {d.DeveloperID,DeveloperName = d.Firs tName ++ d.LastName})。OrderBy(d => d.DeveloperName),DeveloperID,DeveloperName);

返回查看();

}



//

// POST:/ ConferenceAttendants / Create



[HttpPost]

public ActionResult Create (ConferenceAttendant ConferenceAttendant)

{

if(ModelState.IsValid)

{

db.ConferenceAttendants.Add( ConferenceAttendant);

db.SaveChanges();

返回RedirectToAction(Index,Conference);

}

返回查看();

}

how can i remove remove an item from the drop down list once an item has been selected from it in asp.net mvc4? See the process is having a list of conferences and a list of developers now you must select any conference and add a developer to it but i mustnt be able to add the developer twice to the conference? I want to know whether you can do this or whether there is validation for this? This is my controller:

public class ConferenceAttendantController : Controller
{
private PrjctMngmt2Entities db = new PrjctMngmt2Entities();

//
// GET: /ConferenceAttendants/

public ViewResult Index()
{
var ConferenceAttendants = db.ConferenceAttendants.Include("Conference").Include("Developer");
return View(ConferenceAttendants.ToList());
}

//
// GET: /ConferenceAttendants/Create

public ActionResult Create()
{
ViewBag.ConferenceID = new SelectList(db.Conferences.OrderBy(d => d.Name), "ConferenceID", "Name");
ViewBag.DeveloperID = new SelectList(db.Developers.Select(d => new { d.DeveloperID, DeveloperName = d.FirstName + " " + d.LastName }).OrderBy(d => d.DeveloperName), "DeveloperID", "DeveloperName");
return View();
}

//
// POST: /ConferenceAttendants/Create

[HttpPost]
public ActionResult Create(ConferenceAttendant ConferenceAttendant)
{
if (ModelState.IsValid)
{
db.ConferenceAttendants.Add(ConferenceAttendant);
db.SaveChanges();
return RedirectToAction("Index", "Conference");
}
return View();
}

推荐答案

一般来说,你没有。用户不希望项目从下拉列表中消失,所以请不要这样做。



您可以尝试使用选中的列表框进行选择开发者。或者,更常见的是,两个列表中的> (添加)和< (删除)按钮。
Generally, you don't. Users don't expect items to disappear from a drop down list, so please don't do it that way.

You could try using a checked list box for selecting the developers. Or, the more usual, two lists with > (add) and < (remove) buttons between them.


您可以从下拉列表中删除特定的选定项目,并将数据源重新绑定到新的更新记录集。
you can remove the particular selected item from the drop down list and rebind the datasource to the new updates record set.


这篇关于如何从中选择项目后从下拉列表中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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