Reputation: 3241
In an Mvc3 project I have a model class which has a field name InsertDate. I don't want any control on the view for this field.
When data is being saved, it is comed as null and I set it as DateTime.Now on the controller side.
the problem is that: In the update view, this value comes to me null. I want this field to be set its default value in the update view.
Has anyone got an idea about that?
Upvotes: 0
Views: 260
Reputation: 30152
Use a separate view model for each view. Your update view simply excludes that field and sets it uponbupdatkng your model that will go to the database. Use the free tool automapper to copy fields between those models.
Upvotes: 1
Reputation: 30095
Use hidden field to store this data and then it will returns to you.
@Html.HiddenFor(x => x.InsertDate)
Upvotes: 0