Buen dia! Estoy haciendo un programa de carga y muestra de peliculas, La clase pelicula tiene un atributo de tipo DateTime fechalanzamiento. Mi problema es que, cuando cargo la fecha de lanzamiento en formato dd/mm/yyyy no me lo toma. Debo cargar yyyy/mm/dd y tambien me la muestra de esa forma. Mi pregunta es si hay alguna forma no solo de que me muestre la fecha en el formato dd/mm/yyyy sino tambien que me permita cargarla en ese formato! Desde ya, muchas gracias!
Clase Pelicula:
public class Peliculas
{
// Propiedades
public int Id { get; private set; }
public String Nombre { get; set; }
public DateTime FechaSalida { get; set; }
public String Pais { get; set; }
public static int globalPeliculaId;
// Metodos
// Constructores
public Peliculas()
{
this.Nombre = "";
this.FechaSalida = DateTime.Now;
this.Pais = "";
this.Id = Interlocked.Increment(ref globalPeliculaId);
}
public Peliculas(String nombre, int dia, int mes, int anio, String pais)
{
this.Nombre = nombre;
this.FechaSalida = new DateTime(dia, mes, anio); //Validar en Controlador que ingresen aaaa, mm y dd y no otro formato.
this.Pais = pais;
}
}
Controlador peliculas funcion de creacion:
// GET: Peliculas/Create
public ActionResult Create()
{
return View();
}
// POST: Peliculas/Create
[HttpPost]
public ActionResult Create(Peliculas pelicula)
{
try
{
RepoPeliculas.listado.Add(pelicula);
return RedirectToAction("Listado");
}
catch
{
return View();
}
}
Vista Create:
//porcion de codigo de la fecha)
<div class="form-group">
@Html.LabelFor(model => model.FechaSalida, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FechaSalida, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.FechaSalida, "", new { @class = "text-danger" })
</div>
</div>
DateTime
se puede cargar con practicamente cualquier formato de fecha.