How do I call multiple (2) Methods in my Driver?

Topics: Customizing Orchard, Troubleshooting, Writing modules
Jan 10, 2012 at 7:30 PM

I've been calling 1 method in my driver that queries my tables. It's been working just fine. I needed to add another method for a different query and I get errors:

"ERROR_-- Named argument specifications must appear after all fixed arguments have been specified "--

 

My Code:

        protected override DriverResult Display(
            WebinarPart part, string displayType, dynamic shapeHelper) {


            return
                ContentShape("Parts_Webinar",
                                () => shapeHelper.DisplayTemplate(
                                    TemplateName: "Parts/Webinar",
                                   

                                      Model: WebinarService.GetWebinarsForAProductNoZipRequired(part, selectedProductCode: part.ProductCode),
                                             WebinarService.GetWebinarsForAProductByGroupingCode(part, selectedGroupingCode: part.GroupingCode),
                                   Prefix: Prefix));





How do you call multiple Methods in One Driver?

Developer
Jan 10, 2012 at 8:20 PM

I don't know what are you trying to do, but you can't set Model's value this way, it's syntactically incorrect. The Model is a property of an object (a dynamic one here, so you get no Intellisense), so you can only give it one value. That means, you should use a composite object to store the two WebinarService calls' return value.

Jan 10, 2012 at 9:27 PM

Thanks Piedone

Do you know where I can find an example of using a composite object to store the two WebinarService calls' return value?

Jan 10, 2012 at 9:31 PM

And what I am trying to do is, I have a dropdown list that selects a product code from the database. Based on the product code picked the query goes and gathers all the info from the data table based on that Product code. I just want to do the same thing with a seperate table and a different dropdown list/Product Code.

The first One I implemented works fine. But when I try to do the exact same thing with different method, on different Table, It won't let me call both Methods in the Driver.

Developer
Jan 10, 2012 at 9:35 PM

Just define a class (the view model) with two properties to store the two WebinarService values, instantiate it, fill it up and pass it to Model. You could also use an ExpandoObject to avoid defining a new class, but I think that as a Model does weirdly doesn't work.

Jan 10, 2012 at 9:37 PM
Edited Jan 11, 2012 at 7:28 AM
Oceantrain wrote:

Thanks Piedone

Do you know where I can find an example of using a composite object to store the two WebinarService calls' return value?

Like this:

 

public class MyCompositeModel {

    public WebinarServiceCallResponse1 FirstObject { get; set; }
    public WebinarServiceCallResponse2 SecondObject { get; set; }

}

var model = new MyCompositeModel() { ... }

 

The technique of modelling data into a class specifically for your view is commonly referred to as a "ViewModel".

Jan 10, 2012 at 9:38 PM

The 2 Webinar Service values? By that you mean the 2 methods I'm trying to call? Put the 2 methods in a view model? correct?

Developer
Jan 11, 2012 at 10:09 AM

Pete gave you the code too... You could do

model.WebinarServiceCallResponse1 = WebinarService.GetWebinarsForAProductNoZipRequired(part, selectedProductCode: part.ProductCode)
And that with the second response and the second property too.