using System;
using System.ComponentModel.DataAnnotations;
namespace HelloWorldMvcApp
{
public class SampleViewModel
[Required]
public DateTime Date {get;set;}
}
@model HelloWorldMvcApp.SampleViewModel
<!DOCTYPE html>
<html lang="en">
<body>
@Html.TextBoxFor(model => model.Date)
</body>
</html>
using System.Web.Mvc;
using System.Collections.Generic;
public class HomeController : Controller
[HttpGet]
public ActionResult Index()
var model = new SampleViewModel
Date = DateTime.Now
};
return View(model);