This question is locked. New answers and comments are not allowed.
Hi All,
In a typical simple binding of a model to a view you can use the HiddenFor() helper to bring along model values that need to be part of the validation but are properties the user does not set like CustomerID. That class member of the model has the required metadata because it needs to be filled for a successful update or insert.
This is a client binding and the AJAX routine that gets the dataset from the server fills that value into each view model record the grid gets yet in the update handler the Model object contains only the fields represented on the view.
The question is how do you set a HiddenFor() or the like for each row bound to the grid so that when the Model returns in the update method it has those vars intact?
The TryUpdateModel() fails on the first round before the AJAX Update handler is called because of this needed value in the model that is not resident in the viewModel the grid posts to the AJAX handler. At that point it calls the Validate() method again because the code calls TryUpdateModel(). I know this because the class implements the IValidateObject interface and hooks the whole validation processing. The second call to the Validate() routine does not yield a violation because that value was filled in in the AJAX handler right before TryUpdateModel() is called again.
Thanks,
Reid
In a typical simple binding of a model to a view you can use the HiddenFor() helper to bring along model values that need to be part of the validation but are properties the user does not set like CustomerID. That class member of the model has the required metadata because it needs to be filled for a successful update or insert.
This is a client binding and the AJAX routine that gets the dataset from the server fills that value into each view model record the grid gets yet in the update handler the Model object contains only the fields represented on the view.
The question is how do you set a HiddenFor() or the like for each row bound to the grid so that when the Model returns in the update method it has those vars intact?
The TryUpdateModel() fails on the first round before the AJAX Update handler is called because of this needed value in the model that is not resident in the viewModel the grid posts to the AJAX handler. At that point it calls the Validate() method again because the code calls TryUpdateModel(). I know this because the class implements the IValidateObject interface and hooks the whole validation processing. The second call to the Validate() routine does not yield a violation because that value was filled in in the AJAX handler right before TryUpdateModel() is called again.
Thanks,
Reid