modified messagebox problems - why can't I get the data?

Jul 9, 2013 at 10:29 PM

I need to have a search dialog appear, then result in a list of the matched items. As I work through it, I thought I would try to use a messagebox since your messagebox allows me to add fields. Starting with the sample from the article on it, I have most of it working.

However, I am unable to get the values of the textboxes I have added.

Given the following:
Controller.Message("Customer Search",
    model: new CustomerSearchMessageBox(),
    viewName: "SearchMessagebox",
    controllerType: typeof(CustomerController),
    onComplete: r =>
        Debug.WriteLine("the result is: {0}", r.ModelMessageBox.Result);
I can find out which button they pressed. If I stop it and look at "r" in the debugger, I can find the values I have added (under the Modal and View properties). But I can't reference them.

I tried both r.Model.LastName and r.View.DataContext.LastName but while I could clearly see the values in the debugger, VS complained that:

"'CODE.Framework.Wpf.Mvvm.MessageBoxResult' does not contain a definition for 'LastName' and no extension method 'LastName' accepting a first argument of type 'CODE.Framework.Wpf.Mvvm.MessageBoxResult' could be found (are you missing a using directive or an assembly reference?)"

However, r.ModelMessageBox.Result does return the expected value.

I am sure this is really simple, just stumped as to how to get the data, especially when I can see it...


Jul 11, 2013 at 1:48 PM
I haven't played around with getting results back from a Controller.Message, but in the past when we want to get information back from a screen we invoke a new view. something like this:
        private void GetDuplicateInput(CheckForDuplicateCustomerResponse response, CustomerListDataViewModel cust)
            var sinks = new ViewResultEventSinks();
            sinks.ViewClosed += GetDuplicateInputClosed;
            Controller.Action("Customer", "ListDuplicates", new {duplicateList = response.CustomerIdList, customerDataModel = cust}, sinks);

        private void GetDuplicateInputClosed(object sender, ViewResultEventArgs args)
            var duplicateModel = args.ViewResult.Model as CustomerDuplicateListViewModel;
            if (duplicateModel == null) return;
            if (duplicateModel.ContinueSave) Save();
            else Controller.CloseViewForModel(this);
the controller action would add the ViewLevel.Popup, which effectivelly makes it a message box:
        public ActionResult ListDuplicates(List<Guid> duplicateList, CustomerScanViewModel scanViewModel)
            return ViewModal("DuplicateList", new CustomerDuplicateListViewModel(duplicateList, scanViewModel), ViewLevel.Popup);
Now in the GetDuplicateInputClosed you have full access to the public properties exposed on the view model.

Jul 11, 2013 at 6:11 PM

Good to hear from you (and I bet Markus appreciates the additional support!)

Thanks, I will try this and see how it works out. Regardless of it solves this problem, this is good info to know anyway!


Jul 12, 2013 at 12:37 AM
Note: This line you have almost gets you there:
Debug.WriteLine("the result is: {0}", r.ModelMessageBox.Result);
The result object you get (called "r" in your case) has a Model property. You have to cast that to whatever your model is, and you should be good to go:
var myModel = r.Model as CustomerSearchMessageBox();
var text = myModel.FirstName; // Or whatever