Bonjour à tous,
Je bosse avec northwind.
Je suis parvenu à afficher une liste de customer, avec les Actionlink Edit et Detail pour chaque ligne, maintenant je voudrais afficher une vue pour editer une ligne en particulier.
Seul soucis, je n'arrive pas à récupérer la ligne en question (le customer, ou son id pour le retrouver) que faire ?
ma grille :
le controller associé :
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 @model IEnumerable<GestionGridMVC4.ViewModels.Customer> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("Create New", "Create") </p> <table> <tr> <th> @Html.DisplayNameFor(model => model.Customer_ID) </th> <th> @Html.DisplayNameFor(model => model.Company_Name) </th> <th> @Html.DisplayNameFor(model => model.Contact_Name) </th> <th> @Html.DisplayNameFor(model => model.Address) </th> <th> @Html.DisplayNameFor(model => model.City) </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Customer_ID) </td> <td> @Html.DisplayFor(modelItem => item.Company_Name) </td> <td> @Html.DisplayFor(modelItem => item.Contact_Name) </td> <td> @Html.DisplayFor(modelItem => item.Address) </td> <td> @Html.DisplayFor(modelItem => item.City) </td> <td> @Html.ActionLink("Edit", "Edit", new { id = item.Customer_ID }) | <= actionLink me permettant de rentrer dans la méthode Edit du controller "home" @Html.ActionLink("Details", "Details", new { id = item.Customer_ID }) | @Html.ActionLink("Delete", "Delete", new { id = item.Customer_ID }) </td> </tr> } </table>
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 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using BusinessLayer; using Data; namespace GestionGridMVC4.Controllers { public class HomeController : Controller { List<Data.Customer> customerDAL = new List<Customer>(); // // GET: /Home/ public ActionResult Index() { customerDAL = BusinessLayer.CustomerService.LoadCustomers(); List<ViewModels.Customer> customersVM = new List<ViewModels.Customer>(); foreach (Data.Customer item in customerDAL) { customersVM.Add(ConvertDALToVM(item)); } return View(customersVM); } public ActionResult Edit(ViewModels.Customer customer) <= je voudrais récupérer mon customer ici !!! { return View(customer); } } }
Partager