Question: In an MVC project, in my controller, I would like to get data to use in the view.
Lets say I want to retrieve a `List<string>` and an `int`.

My controller's method declaration is similar to this.

```
void GetFooData(int id, out List<string> listData, out int aValue);

```

In the view I am using as so:

```
List<string> data;
int value;
controller.GetFooData(myId, data, value);

```

I do not like this approach. How can I retrieve data in a prettier way without using a data wrapper class?

Answer: 
Despite you not using the MVC pattern correctly, in general, there are a lot of ways to return multiple things from a method. Typically one of:

* Use `out` parameters (as you did above)
* Return a `Tuple` to hold multiple items
* Define and return a wrapper `class` to hold multiple items in its properties (this is classically the 'best practice')
* Return a `dynamic` and/or `ExpandoObject`

There are probably more that I can't think of right now...
You should create a value object to hold your data to be returned. I have a fellow-programmer who says "out parameters are for weenies and college students". No offense to college students and weenies, but I tend to agree with the sentiment... I don't use out parameters EVER.

The cleanest way to solve your problem at hand is like this:

```
public class FooData
{
    public List<string> Strings { get; set; }
    public int MyInt { get; set; }
}

public FooData GetFooData(int id)
{
    var fooStrings = _stringRepository.GetFooStrings(id); 
    //or wherever you're getting your data from

    return new FooData
                {
                    Strings = fooStrings,
                    MyInt = id, //or whatever the int prop is supposed to be
                };
}

```

A great rule-of-thumb that I learned from Bob Martin's book, "Clean Code", is this: If there is data to be returned, return it. If you have more than one type of date to be returned, load them in a wrapper class. It'll make your life easier, and the next guy who has to look at your code will spend less time scratching his head.

**EDIT:** 

In case you're new to C#, I thought I'd add one bit of explanation. Your method starts with `void`. That means that it doesn't return anything. Yes, there are out parameters, but you've probably already removed them. :) Instead of `void`, your method needs to return a type. If you only had one type of data to return, like `List<string>`, you could say `List<string> GetFooData(int id)`, etc. In my example above, I added the new class/type called `FooData` to the method so that it returns `FooData`. Hope this helps. If you already knew all that, sorry for stating the "obvious". (get rid of your out parameters!)

**ANOTHER EDIT:**

If you're trying to make this work with ASP.NET MVC, as the other commenters suggest, you should do it the "MVC" way. If you have a view that needs data, give it a view model like this:

```
public ViewResult SomeViewWithFooData(int id)
{
    var fooStrings = _stringRepository.GetFooStrings(id); 
        //or wherever you're getting your data from

    var fooData = new FooData
                    {
                        Strings = fooStrings,
                        MyInt = id, //or whatever the int prop is supposed to be
                    };

    return new View(fooData);  
}

```

Then, you can have a view called `SomeViewWithFooData` that inherits from `System.Web.Mvc.ViewPage<FooData>`. Inside you're view, just call `Model` to get at your data. At that point, `Model` is of type FooData.

`<%=Model.MyInt %>` is your int passed to the view from the controller action.

`<%=Model.Strings %>` is your list of strings.