InputNumber
InputNumber
Form
This sample shows how to use input controls in a form.
Features
Description
This sample shows how to use input controls in a form.
You can also use model binding features at the same time.
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 | using System; using Microsoft.AspNetCore.Mvc; using MvcExplorer.Models; using System.Collections.Generic; namespace MvcExplorer.Controllers { public partial class InputNumberController : Controller { private List< string > countries = Countries.GetCountries(); private List< string > products = Products.GetProducts(); public ActionResult Form() { ViewBag.Countries = countries; ViewBag.Products = products; var model = new CustomerOrder { ID = 101, OrderTime = DateTime.Now, Product = "PlayStation 4" }; return View(model); } [HttpPost] public ActionResult Form(CustomerOrder model) { ViewBag.Countries = countries; ViewBag.Products = products; if (ModelState.IsValid) { ViewBag.Message = Localization.InputNumberRes.Form_Message; } return View(model); } } } |
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 | @model CustomerOrder @ { string message = ViewBag.Message; List< string > countries = ViewBag.Countries; List< string > products = ViewBag.Products; countries.Insert(0, "" ); } < div > < form asp-anti-forgery = "true" asp-action = "Form" > < div asp-validation-summary = "All" > </ div > < div > < label asp-for = "@Model.Country" ></ label > < c1-auto-complete for = "@Model.Country" > < c1-items-source source-collection = "@countries" ></ c1-items-source > </ c1-auto-complete > < span asp-validation-for = "@Model.Country" ></ span > </ div > < div > < label asp-for = "@Model.Product" ></ label > < c1-combo-box for = "@Model.Product" > < c1-items-source source-collection = "@products" ></ c1-items-source > </ c1-combo-box > < span asp-validation-for = "@Model.Product" ></ span > </ div > < div > < label asp-for = "@Model.Price" ></ label > < c1-input-number for = "@Model.Price" ></ c1-input-number > < span asp-validation-for = "@Model.Price" ></ span > </ div > < div > < label asp-for = "@Model.Count" ></ label > < c1-input-number for = "@Model.Count" ></ c1-input-number > < span asp-validation-for = "@Model.Count" ></ span > </ div > < div > < label asp-for = "@Model.OrderTime" ></ label > < c1-input-date-time for = "@Model.OrderTime" ></ c1-input-date-time > < span asp-validation-for = "@Model.OrderTime" ></ span > </ div > < div style = "margin-top: 10px" > < input type = "submit" class = "wj-btn wj-btn-default" value = "@(InputNumberRes.Form_Submit)" /> </ div > </ form > </ div > < p > @message</p> @section Description{ < p > @Html .Raw(InputNumberRes.Form_Text0)</ p > < p > @Html .Raw(InputNumberRes.Form_Text1)</ p > } |