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())
- {
- // ReSharper disable once LoopCanBeConvertedToQuery
- 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:

Francesco BigiPosted Feb 7, 2017, 7:10 AM
I have done this, and it seem it is working:
Catcher WongPosted Feb 5, 2017, 8:49 AM
Francesco BigiPosted Feb 5, 2017, 8:35 AM
@Catcher Wong
Yes I am using EF.But I show you my map:
I have created a folder DALEF, where I have my connection, with my db.
On my Models folder I have created my personalize class, in order to give required attributes.
And I have created a folder called DAL where I created the class where it says that my model class property are the same as the db properties.
Catcher WongPosted Feb 5, 2017, 8:05 AM
Francesco BigiPosted Feb 5, 2017, 6:26 AM
I have created my own class which refers to my db.
And I don't know how to include, when I do the scaffolding, I can see your example that works fine, but without scaffolding how to do?
Catcher WongPosted Feb 4, 2017, 9:00 PM