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
rahul patil
NA
160
8.4k
how to display a list data from controller to view?
Jun 7 2020 6:04 AM
I want to display a list data form controller to view
I m getting error:
student.cs
public
class
Employee
{
public
int
Id {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
string
Designaton {
get
;
set
; }
}
HomeController.cs
public
ActionResult Index()
{
List<Employee> emplist =
new
List<Employee>() {
new
Employee(){ Id=1, Name=
"Steve"
, Designaton =
"hr"
},
new
Employee(){ Id=2, Name=
"Bill"
, Designaton =
"finance"
},
new
Employee(){ Id=3, Name=
"Ram"
, Designaton =
"hr"
},
new
Employee(){ Id=4, Name=
"Ron"
, Designaton =
"finance"
},
new
Employee(){ Id=5, Name=
"Rob"
, Designaton =
"finance"
}
};
ViewBag.totalemp = emplist.Count();
return
View();
}
Index.cshtml
@{
ViewBag.Title =
"Index"
;
}
<h2>Index</h2>
<td>@((ViewBag.totalemp
as
IEnumerable<migrationdemo.Models.Employee>))</td>
@
foreach
(var item
in
ViewBag.totalemp)
{
@item.Id
@item.Name
@item.Designaton
}
I want to displaying all data but now i am facing error?
Reply
Answers (
3
)
Payment gateway callback action method executing multiple
how to render the another view(blog) inside the index view?