How to get Model binding errors from Part driver?

Topics: Core, General, Troubleshooting, Writing modules
Mar 25, 2013 at 6:56 PM
I have a part that's failing to save due to a postback error. I know what the error is, but I had to step through the code in order to get the error message (I'm using knockout, and passing json in a hidden field as part of a form POST, i plan to try to have a custom valueprovider be able to handle mixed form-encoded + json binding).

The call to TryUpdateModel returns false, but no error shows up in the logs, and nothing is passed to INotifier, so no error shows up on the UI (I do get a blank red box at the point where @Html.ValidationSummary() is placed). I think it's because the error is at the binding step, and not the validation one. Is there a way for me to access the ModelState for my part, so I can access the error messages? IUpdateModel interface has a method to add errors, but no methods to get errors. In this case how am I supposed to find error messages?

This is all happening here:

    protected override DriverResult Editor(MyPart part, IUpdateModel updater, dynamic shapeHelper) {
        var vm = new EditMyPartViewModel();
        bool mongoSavedOK = false;

        // This call returns false, but how do I access the errors?
        if (updater.TryUpdateModel(vm, Prefix, null, null)) {

Mar 25, 2013 at 9:05 PM
It's not clean, as it breaks the abstraction, but you can cast updater to Controller and access its ModelState.
Mar 25, 2013 at 9:22 PM
Thanks! You're right that it is not ideal, but it'll have to do if there's no other way.