MultiSelect
Form
Features
Sample
Description
This sample shows how to use MultiSelect in a form.
Source
FormController.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MvcExplorer.Models; using System.Collections.Specialized; namespace MvcExplorer.Controllers { public partial class MultiSelectController : Controller { private IList<string> products = Products.GetProducts(); public ActionResult Form() { ViewBag.Products = products; var model = new CustomerProduct() { Products = new string[]{}}; return View(model); } [HttpPost] public ActionResult Form(CustomerProduct model) { ViewBag.Products = products; if (model.Products != null && model.Products.Length > 0) { ViewBag.Message = string.Format(Resources.MultiSelect.Form_Message, string.Join(", ", model.Products)); } return View(model); } } }
Form.cshtml
@using MvcExplorer.Models; @model CustomerProduct @{ String message = ViewBag.Message; List<string> products = ViewBag.Products; } <label>@Html.Raw(Resources.MultiSelect.Form_Text0)</label> <div> @using (Html.BeginForm()) { <div> @(Html.C1().MultiSelectFor(model=>model.Products).Bind(products) .Placeholder(Resources.MultiSelect.Form_Placeholder) .HeaderFormat(Resources.MultiSelect.Form_HeaderFormat) ) </div> <div style="margin-top: 10px"> <input type="submit" class="wj-btn wj-btn-default" value="@(Resources.MultiSelect.Form_Submit)" /> </div> } <p>@message</p> </div> @section Description{ <p>@Html.Raw(Resources.MultiSelect.Form_Text1)</p> }
Documentation