TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Francesco Bigi
1.7k
57
82.1k
Asp.net MVC . How to display name instead of ID in view page
Feb 4 2017 12:32 PM
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:
Reply
Answers (
6
)
Alert while clicking the button with matching the gridview l
I want to update the leftdays, Row by Row .not all at once.