Salut,

J'ai un contact qui peut avoir plusieurs catégories, j'aimerai rajouter une listbox avec toutes les catégories disponible mais je débute en MVC.

Voici mon controller:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
public ActionResult Edit(long id = 0)
        {
            Contact contact = db.Contact.Find(id);
            if (contact == null)
            {
                return HttpNotFound();
            }
            ViewBag.SocietyID = new SelectList(db.Society, "ID", "Name", contact.SocietyID);
            return View(contact);
        }
1) Il faut récupérer une list de catégorie ici?

Ici ma classe Contact
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public partial class Contact
    {
        public Contact()
        {
            this.Comment = new HashSet<Comment>();
            this.Account = new HashSet<Account>();
        }
 
        public long ID { get; set; }
        public string Email { get; set; }
        public string Password { get; set; }
        public string Firstname { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }
        public string Tel { get; set; }
        public string GSM { get; set; }
        public Nullable<bool> IsAdmin { get; set; }
        public string ZipCode { get; set; }
        public Nullable<long> SocietyID { get; set; }
 
        public virtual ICollection<Comment> Comment { get; set; }
        public virtual Society Society { get; set; }
        public virtual ICollection<Category> Category{ get; set; }
    }

2) Que faut-il mettre dans la vue (@Html.ListBox())?

Dans ma vue j'ai ceci (@model SocialLink.Models.Contact)
Est ce que je pourrai rajouter d'autres classes?

Merci de votre aide