i am trying to update model with some changes like below
inventory.SiteId=Siteitem.Siteid;
inventory.CreatedBy=currentuser;
inventory.CreatedDate=DateTime.Today;
TryUpdateModel(inventory);
or
UpdateModel(inventory);
both are failed to update the model
So the question is "Why is it failing?" One thing you could look at is the ModelState dictionary and see if the model is is valid and if there are errors. There's a reason it's failing, of course. I think that would be one of my first checks. Maybe you've got a mismatch of some sort - integer on one side and string on the other, for instance.
Remember here that TryUpdateModel updates the model with values from your form. Are you trying to update the model in your database? If so you need to specify this. If you set inventory.Whatever above, your model is already set with those values.
The only time to call TryUpdateModel is when you want to take those form values and put them into the model and set ModelState (which will then contain any errors as part of this process as well)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With