Hello People!
I don't know how to show the the name instead of the ID
As you can see on the sub category, it is showing me the id result instead of the.
I have a table related with another table, on my sql db.
I made a connection string to my MVC project.
These are my codes:
Models -> ArticleModels.cs
- public class ArticleModels
- {
- public int ART_Id { get; set; }
-
- [Display(Name = "Sous Categorie")]
- public int ART_SCAT_Id { get; set; }
-
- [Display(Name = "Libelle")]
- public string ART_Libelle { get; set; }
-
- [Display(Name = "Description")]
- public string ART_Description { get; set; }
-
- [Display(Name="Prix")]
- public decimal ART_Prix { get; set; }
- [Display(Name = "Stock")]
- public int ART_Stock { get; set; }
- }
DAL -> ArticleBL.cs
- public static List SelectAllArticle()
- {
- var rtn = new List();
- using (var context = new WebShopEntities())
- {
-
- foreach (var item in context.Article)
- {
- rtn.Add(new ArticleModels
- {
- ART_Id = item.ART_Id,
- ART_SCAT_Id = item.ART_SCAT_Id,
- ART_Libelle = item.ART_Libelle,
- ART_Description = item.ART_Description,
- ART_Prix = item.ART_Prix,
- ART_Stock = item.ART_Stock
- });
- }
-
- }
- return rtn;
- }
Controllers ->
ArticleControllers.cs - public ActionResult Index()
- {
- var lstClient = ArticleBL.SelectAllArticle().ToList();
- return View(lstClient);
- }
Views -> Article -> Index.cshtml
- @foreach (var item in Model)
- {
- <tr>
- <td>
- @Html.DisplayFor(modelItem => item.ART_SCAT_Id)
- td>
- <td>
- @Html.DisplayFor(modelItem => item.ART_Libelle)
- td>
- <td>
- @Html.DisplayFor(modelItem => item.ART_Description)
- td>
- <td>
-
- @Html.DisplayFor(modelItem => item.ART_Prix)
- <span class="glyphicon glyphicon-eur">span>
- td>
- <td>
- @Html.DisplayFor(modelItem => item.ART_Stock)
- td>
- <td>
- @Html.ActionLink("Details", "Details", new { id=item.ART_Id }) |
- @Html.ActionLink("Buy", "Edit", null, new {@class = "btn btn-warning glyphicon glyphicon-shopping-cart"})
- td>
- tr>
- }
These are my tables: