Bonsoir,
J'ai entrain de développer une application ASP. Net MVC 3 en utilisant C # et SQL Server 2005. Je veux charger les données de ma base de données dans un ListBox.
Bref, j'ai fait beaucoup de Recherches mais je ne trouve rien où Entity Framework est utilisé.
En faite, j'ai essayé de solution mais toujours VS n'acceptait pas la syntaxe.

Cette ma classe modèle :
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
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;
using System.Data.SqlClient;
using System.Data.Entity;
namespace MvcApplication2.Models
{
    public class Profile_Ga
    {
        [Key]
        public string ID_Gamme { get; set; }
        public string In_Ga { get; set; }
        public string Out_Ga { get; set; }
        public string Next_Gamme { get; set; }
        public string Etat { get; set; }
 }
}
Je veux afficher les ID_Gamme dans une listeBox.
Dans le View, j'ai essayé de faire comme ceci mais le syntaxe n'est pas accepté :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
<%: Html.ListBoxFor(model => model.ID_Gamme) %>
et voilà mon controlleur :

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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication2.Models;
 
namespace MvcApplication2.Controllers
{ 
    public class ProfileGaController : Controller
    {
        private GammeContext db = new GammeContext();
 
        //
        // GET: /ProfileGa/
 
        public ViewResult Index()
        {
 
            return View(db.Profil_Gas.ToList());
        }
 
        //
        // GET: /ProfileGa/Details/5
 
        public ViewResult Details(string id)
        {
            Profile_Ga profile_ga = db.Profil_Gas.Find(id);
            return View(profile_ga);
        }
 
        //
        // GET: /ProfileGa/Create
 
        public ActionResult Create()
        {
 
            return View();
        } 
 
        //
        // POST: /ProfileGa/Create
 
        [HttpPost]
        public ActionResult Create(Profile_Ga profile_ga)
        {
            if (ModelState.IsValid)
            {
                db.Profil_Gas.Add(profile_ga);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }
 
            return View(profile_ga);
        }
 
        //
        // GET: /ProfileGa/Edit/5
 
        public ActionResult Edit(string id)
        {
            Profile_Ga profile_ga = db.Profil_Gas.Find(id);
            return View(profile_ga);
        }
 
        //
        // POST: /ProfileGa/Edit/5
 
        [HttpPost]
        public ActionResult Edit(Profile_Ga profile_ga)
        {
            if (ModelState.IsValid)
            {
                db.Entry(profile_ga).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(profile_ga);
        }
 
        //
        // GET: /ProfileGa/Delete/5
 
        public ActionResult Delete(string id)
        {
            Profile_Ga profile_ga = db.Profil_Gas.Find(id);
            return View(profile_ga);
        }
 
        //
        // POST: /ProfileGa/Delete/5
 
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(string id)
        {            
            Profile_Ga profile_ga = db.Profil_Gas.Find(id);
            db.Profil_Gas.Remove(profile_ga);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
 
        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}
Y-a-t-il une solution ?