UpdateModel() will set your model's properties to whatever was present in the form. If your user typed a Shamsi-style date, that's what the OrderDate property will be set to. What you can do is call UpdateModel()
before your ShamsiToMiladi conversion function. Or you can put a [Bind(Exclude = "OrderDate")] attribute on your model type, which signals to UpdateModel() that it should never set that property.
rezaiy.ali
Member
91 Points
170 Posts
New value dosn't set for UpdateModel
May 01, 2010 05:48 PM|LINK
hi
this is the code i am using for update model
Project NewProject = _projectRepository.GetProject(Id); NewProject.OrderDate = GenralClasses.FarsiDate.ShamsiToMiladi(Request.Form["OrderDate"].ToString()); UpdateModel(NewProject); _projectRepository.Save();on the line 2 i set new value to OrderDate
but after this step OrderDate get value of text box in view.
the value of text box is shamsi date and on line 2 i convert that date to miladi date.
why OrderDate get shamsi date?
ignatandrei
All-Star
134989 Points
21641 Posts
Moderator
MVP
Re: New value dosn't set for UpdateModel
May 01, 2010 07:17 PM|LINK
because you call UpdateModel AFTER defining your Orderdate
Try inverse
UpdateModel(NewProject);
NewProject.OrderDate = GenralClasses.FarsiDate.ShamsiToMiladi(Request.Form["OrderDate"].ToString());
levib
Star
7702 Points
1099 Posts
Microsoft
Re: New value dosn't set for UpdateModel
May 01, 2010 07:18 PM|LINK
UpdateModel() will set your model's properties to whatever was present in the form. If your user typed a Shamsi-style date, that's what the OrderDate property will be set to. What you can do is call UpdateModel() before your ShamsiToMiladi conversion function. Or you can put a [Bind(Exclude = "OrderDate")] attribute on your model type, which signals to UpdateModel() that it should never set that property.