Skip to content

Instantly share code, notes, and snippets.

@cleytonferrari
Created August 30, 2012 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleytonferrari/3542947 to your computer and use it in GitHub Desktop.
Save cleytonferrari/3542947 to your computer and use it in GitHub Desktop.
Exemplo de Data em ASP.Net MVC 4
using System;
using System.Web.Mvc;
using ExemploDeDataPreenchida.Models;
namespace ExemploDeDataPreenchida.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
var produto = new Produto
{
DataVencimento = DateTime.Now
};
return View(produto);
}
}
}
@model ExemploDeDataPreenchida.Models.Produto
@{
ViewBag.Title = "Exemplo de data preenchida";
}
<h2>Exemplo de data preenchida</h2>
<form action="" method="GET">
Nome:
<input type="text" name="Nome" id="Nome" value=""/>
<br/>
Data
<input type="text" nome="DataVencimento" id="DataVencimento" value="@Model.DataVencimento"/>
<br/>
<input type="submit" value="Enviar"/>
</form>
using System;
using System.ComponentModel.DataAnnotations;
namespace ExemploDeDataPreenchida.Models
{
public class Produto
{
public int ProdutoId { get; set; }
public string Nome { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime DataVencimento { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment