Skip to content

Instantly share code, notes, and snippets.

@kristofclaes
Created June 25, 2012 07:37
Show Gist options
  • Save kristofclaes/2987174 to your computer and use it in GitHub Desktop.
Save kristofclaes/2987174 to your computer and use it in GitHub Desktop.
HomeController.cs
using System;
using System.Web.Mvc;
namespace MvcApplication21.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new Models.TestModel { DateNaissance = DateTime.Now });
}
}
}
@model MvcApplication21.Models.TestModel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>TestModel</legend>
<div class="editor-label">
@Html.LabelFor(model => model.DateNaissance)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DateNaissance)
@Html.ValidationMessageFor(model => model.DateNaissance)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
using System;
using System.ComponentModel.DataAnnotations;
namespace MvcApplication21.Models
{
public class TestModel
{
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime DateNaissance { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment