ListBox
Multi-select
This sample shows how to select multiple items of the ListBox control.
Features
Description
This sample shows how to select multiple items of the ListBox control.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Data.Entity.Validation; using System.Data; using C1.Web.Mvc; using C1.Web.Mvc.Serialization; using MvcExplorer.Models; using System.Data.Entity; namespace MvcExplorer.Controllers { public partial class ListBoxController : Controller { private C1NWindEntities db = new C1NWindEntities(); public ActionResult MultiSelect() { return View(db); } public ActionResult ListUpdateProducts([C1JsonRequest]CollectionViewEditRequest<Product> requestData) { return this .C1Json(CollectionViewHelper.Edit<Product>(requestData, item => { string error = string .Empty; bool success = true ; try { db.Entry(item as object ).State = EntityState.Modified; db.SaveChanges(); } catch (DbEntityValidationException e) { error = string .Join( "," , e.EntityValidationErrors.Select(result => { return string .Join( "," , result.ValidationErrors.Select(err => err.ErrorMessage)); })); success = false ; } catch (Exception e) { error = e.Message; success = false ; } return new CollectionViewItemResult<Product> { Error = error, Success = success && ModelState.IsValid, Data = item }; }, () => db.Products.ToList<Product>())); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | @model C1NWindEntities @ (Html.C1().ListBox() .Bind(ib => ib.Bind(Model.Products) .Update(Url.Action( "ListUpdateProducts" ))) .DisplayMemberPath( "ProductName" ) .CheckedMemberPath( "Discontinued" ) .Width(400).Height(200) ) @section Description{ @Html .Raw(Resources.ListBox.MultiSelect_Text0) } |