Good day! I'm doing a program of loading and showing movies, The movie class has an attribute of type DateTime release date. My problem is that, when I upload the release date in dd / mm / yyyy format, I do not take it. I have to load yyyy / mm / dd and also show it to me that way. My question is if there is any way not only to show me the date in the dd / mm / yyyy format but also to allow me to upload it in that format! Thank you very much!
Movie Class:
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;
}
}
Controller films creation function:
// 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();
}
}
Create View:
//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>