MultiSelect
Form
Features
Sample
Description
This sample shows how to use MultiSelect in a form.
Source
FormController.cs
using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Linq; using MvcExplorer.Models; 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(Localization.MultiSelectRes.Form_Message, string.Join(", ", model.Products)); } return View(model); } } }
Form.cshtml
@model CustomerProduct @{ String message = ViewBag.Message; List<string> products = ViewBag.Products; } <label>@Html.Raw(MultiSelectRes.Form_Text1)</label> <div> <form asp-action="Form"> <div> <c1-multi-select for="@Model.Products" placeholder="@MultiSelectRes.Form_Placeholder" header-format="@MultiSelectRes.Form_HeaderFormat" > <c1-items-source source-collection="products" /> </c1-multi-select> </div> <div style="margin-top: 10px"> <input type="submit" class="wj-btn wj-btn-default" value="@(MultiSelectRes.Form_Submit)" /> </div> </form> <p>@message</p> </div> @section Description{ <p>@Html.Raw(MultiSelectRes.Form_Text0)</p> }
Documentation