Example of TimePickerFor in ASP.NET MVC TimePicker Control
Click/Touch the submit button to post the selected value in the TimePicker. When posting the null value, validation error message will be shown below the TimePicker.
@Html.UiTimePickerFor(model => model.objectValue, new UiTimePickerOptions { Width = "200px" })
@Html.UiButton(new UiButtonOptions { Id = "btn", Text = "Post", Type = UiButtonType.Submit, Color = UiButtonColor.Primary })
<style>
#wrapper { max-width: 246px; margin: 30px auto; padding-top: 50px; }
#submitbutton { margin-top: 20px; margin-left: 65px; }
.field-validation-error { color: red; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
@model CalendarsDemoController.TimePickerModel
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<div class="control-section">
<div id="wrapper">
@Html.UiTimePickerFor(model => model.objectValue, new UiTimePickerOptions { Width = "200px" })
<div>
@Html.ValidationMessageFor(model => model.objectValue)
</div>
<div id="submitbutton">
@Html.UiButton(new UiButtonOptions { Id = "btn", Text = "Post", Type = UiButtonType.Submit, Color = UiButtonColor.Primary })
</div>
</div>
</div>
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TimePickerController : Controller
{
// The page is Views/TimePicker/TimePickerFor.cshtml; it draws what ViewData holds.
public ActionResult TimePickerFor()
{
var model = new TimePickerModel();
model.objectValue = DateTime.Now;
return View(model);
}
[HttpPost]
public ActionResult TimePickerFor(TimePickerModel model)
{
// the posted value is obtained from the model
return View(model);
}
public class TimePickerModel
{
[Required(ErrorMessage = "Value is required")]
public DateTime? objectValue { get; set; }
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
This sample demonstrates the Strongly typed extension support in TimePicker. Value is set to the TimePicker from the code behind and its set to TimePicker in view page by invoking the strongly typed TimePickerFor helper with the lamba expression.