Take the 2-minute tour ×

In my application i have 'Contacts' & 'Invitations' When i want to create new Invitation i want the user to select whom to invite from his contacts 'Using multiple check boxes for example. In the Invitation Controller , i want to pass an invitation model to the view as well as a list of contacts that the user has.

How can i do this in ASP.net MVC 3 any ideas ?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Why don't you have a complex type Model? Something like:

public class MyModel
    public Invitation Invitation { get; set; }
    public List<Contact> Contacts { get; set; }

Then in the view your model declaration is (assuming you're using razor):

@model MyModel
share|improve this answer
came here to suggest exactly the same :-) +1 –  Brian Scott Apr 20 '12 at 12:05
How about using a ViewModel ? is it a good alternative :) –  iyad al aqel Apr 20 '12 at 12:09
MyModel is a ViewModel ;) –  Raphaël Althaus Apr 20 '12 at 12:11
@iyadalaqel yeah MyModel is a ViewModel as Raphael said :) –  mattytommo Apr 20 '12 at 12:22

2 choices :

  • using a ViewModel (new class with references to all the classes you need)
  • using a class as Model and a ViewBag for the second class
share|improve this answer
mmm i'm using the second choice as of now , but how can i loop over the list of second class in the ViewBag ? –  iyad al aqel Apr 20 '12 at 12:09
if it's enumerable... foreach. If you don't want a foreach (but a for), you have to "recast" your ViewBag, which is dynamic : IList<Contacts> contacts = ViewBag.Contacts (and use contacts) –  Raphaël Althaus Apr 20 '12 at 12:12
Why do always view bags come on when talking MVC, I've written an entire enterprise app without the need for them. –  Anders Apr 20 '12 at 12:26
They exist... and so CAN be used. Of course they CAN be avoided. That's not because you don't need/like them that no one should use them, no ? –  Raphaël Althaus Apr 20 '12 at 12:30
Well, I try to abstract MVC away from my Models to make it easier to test etc, if you can avoid them I think you should –  Anders Apr 20 '12 at 12:35

Your Answer


