InputNumber
InputNumber
Form
Features
Sample
Description
This sample shows how to use input controls in a form.
You can also use model binding features at the same time.
Source
FormController.cs
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); } } }
Form.cshtml
@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> }
Documentation