Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
6
Reply
Asp.net MVC . How to display name instead of ID in view page
Francesco Bigi
Feb 4 2017 12:32 PM
2.3k
Reply
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())
{
// 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:
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
6
)
Next Recommended Forum
Alert while clicking the button with matching the gridview l
I want to update the leftdays, Row by Row .not all at once.