InputNumber
説明
このサンプルは、フォームの入力コントロールを使用する方法を示します。
また、同時にモデル連結を使用することができます。
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 | using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using MvcExplorer.Models; 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 = Resources.InputNumber.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 | @model MvcExplorer.Models.CustomerOrder @ { string message = ViewBag.Message; List< string > countries = ViewBag.Countries; List< string > products = ViewBag.Products; countries.Insert(0, "" ); } < div > @using (Html.BeginForm()) { @Html .AntiForgeryToken() @Html .ValidationSummary() < div > @Html .LabelFor(m => m.Country) @Html .C1().AutoCompleteFor(m=>m.Country).Bind(countries) @Html .ValidationMessageFor(m=>m.Country) </ div > < div > @Html .LabelFor(m => m.Product) @Html .C1().ComboBoxFor(m=>m.Product).Bind(products) @Html .ValidationMessageFor(m=>m.Product) </ div > < div > @Html .LabelFor(m => m.Price) @Html .C1().InputNumberFor(m => m.Price) @Html .ValidationMessageFor(m => m.Price) </ div > < div > @Html .LabelFor(m => m.Count) @Html .C1().InputNumberFor(m => m.Count) @Html .ValidationMessageFor(m => m.Count) </ div > < div > @Html .LabelFor(m => m.OrderTime) @Html .C1().InputDateTimeFor(m => m.OrderTime) @Html .ValidationMessageFor(m => m.OrderTime) </ div > < div style = "margin-top: 10px" > < input type = "submit" class = "wj-btn wj-btn-default" value = "@(Resources.InputNumber.Form_Submit)" /> </ div > } </ div > < p > @message</p> @section Description{ < p > @Html .Raw(Resources.InputNumber.Form_Text1)</ p > < p > @Html .Raw(Resources.InputNumber.Form_Text2)</ p > } |