mardi 17 novembre 2015

how to prevent set default value if property has already value in edit view and model in mvc

I am working on edit view, i want set the default value for Create_Time and Last_Update

here is model

public class TVSerialEpisode
{
    private DateTime _CurrentTime = DateTime.Now;
    [Key]
    public Int64 Video_ID { get; set; }
    public string Episode_Name { get; set; }
    public string Description { get; set; }
    public bool Is_Active { get; set; }
    public DateTime Create_Time
    {
        get { return _CurrentTime; }
        set { _CurrentTime = value; }
    }
    public DateTime Last_Update
    {
        get { return _CurrentTime; }
        set { _CurrentTime = value; }
    }
}

here is controller

 public ActionResult EditEpisode(TVSerialEpisode tvepisode)
    {
        if (ModelState.IsValid)
        {
            tvContext.Entry(tvepisode).State = EntityState.Modified;                
            tvContext.SaveChanges();
            return RedirectToAction("ListAllEpisode"});
        }
        return View(tvepisode);
    }

i am not sending Create_Time and Last_Update value from view. And it is working fine with create view. But the problem is that when i am trying to edit view and save it then it also set the default value for Create_Time and Last_Update , but i want only Last_Update should be update, not Create_Time

Aucun commentaire:

Enregistrer un commentaire