Hidden For a View Model attribute - getting changed property EF
I need to know if 2 attributes have been changed, in order to do some
stuff. I think there should be 2 approaches, but I can't figure it out.
I created a ViewModel with an attribute for the old value. In my view:
@{DateTime date =
Convert.ToDateTime(Model.event.fromDate.ToShortDateString());}
@Html.HiddenFor(m => m.previousDate, new { @Value = date })
@Html.TextBoxFor(model =>
model.event.fromDate,"{0:dd/MM/yyyy}",new{@class="date"})
In the view Model:
....
public Event event {get; set;}
public DateTime previousDate {get; set;}
And my Event class:
....
DateTime fromDate { get; set; }
When I post the view, the "previousDate" attribute of the ViewModel comes
with default time '01/01/1901', and not the one that I set.
I think other approach could be to get changed properties from entity
framework, but I haven't been able to do it either.
No comments:
Post a Comment