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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | using System; using System.Linq; using Microsoft.AspNetCore.Mvc; using System.Data.SqlClient; using C1.Web.Mvc; using C1.Web.Mvc.Serialization; using MvcExplorer.Models; using Microsoft.EntityFrameworkCore; namespace MvcExplorer.Controllers { public partial class ListBoxController : Controller { private readonly C1NWindEntities _db; public ListBoxController(C1NWindEntities db) { _db = db; } 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 (Exception e) { error = GetExceptionMessage(e); success = false ; } return new CollectionViewItemResult<Product> { Error = error, Success = success, Data = item }; }, () => _db.Products.ToList<Product>())); } // Get the real exception message internal static string GetExceptionMessage(Exception e) { var msg = e.Message; var sqlException = GetSqlException(e); if (sqlException != null ) { msg = sqlException.Message; } return msg; } /// <summary> /// In order to get the real exception message. /// </summary> private static SqlException GetSqlException(Exception e) { while (e != null && !(e is SqlException)) { e = e.InnerException; } return e as SqlException; } } } |
1 2 3 4 5 6 7 8 9 | @model C1NWindEntities < c1-list-box width = "400px" height = "200px" display-member-path = "ProductName" checked-member-path = "Discontinued" > < c1-items-source update-action-url = "ListUpdateProducts" source-collection = "@Model.Products" ></ c1-items-source > </ c1-list-box > @section Description{ @Html .Raw(ListBoxRes.MultiSelect_Text0) } |