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
ahmed elbarbary
NA
1.6k
275.3k
How to pass value of lastrecord from controller to view whe
Jan 6 2019 11:48 PM
problem
How to pass value of last record from controller to view when click on last button .
I have controller employee have action create
In this action create I have view for create action
on view create i have button Last
this button when i press on it i need it get last record
if table employee have employeeid from 1 to 5 and click on last button it must go to record 5 and show it
so that what i do as below
public
IActionResult Create()
{
var results = _context.GetAll().OrderBy(Employee => Employee.EmployeeId).LastOrDefault();
return
View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public
async Task<IActionResult> Create(Employee employee)
{
}
on view create
<div
class
=
"title_of_div"
>
<button id=
"BtnLast"
style=
"display: inline"
><b>Last</b></button>
</div>
<div
class
=
"row"
>
<div
class
=
"col-md-4"
>
<form asp-action=
"Create"
>
<div asp-validation-summary=
"ModelOnly"
class
=
"text-danger"
></div>
<div
class
=
"form-group"
>
<label asp-
for
=
"EmployeeId"
class
=
"control-label"
></label>
<input asp-
for
=
"EmployeeId"
class
=
"form-control"
/>
<span asp-validation-
for
=
"EmployeeId"
class
=
"text-danger"
></span>
</div>
<div
class
=
"form-group"
>
<label asp-
for
=
"EmployeeName"
class
=
"control-label"
></label>
<input asp-
for
=
"EmployeeName"
class
=
"form-control"
/>
<span asp-validation-
for
=
"EmployeeName"
class
=
"text-danger"
></span>
</div>
<div
class
=
"form-group"
>
<label asp-
for
=
"EmployeeAge"
class
=
"control-label"
></label>
<input asp-
for
=
"EmployeeAge"
class
=
"form-control"
/>
<span asp-validation-
for
=
"EmployeeAge"
class
=
"text-danger"
></span>
</div>
<div
class
=
"form-group"
>
<input type=
"submit"
value=
"Create"
class
=
"btn btn-default"
/>
</div>
</form>
</div>
</div>
technology used asp.net core 2.1 visual studio 2017 sql server 2012
Reply
Answers (
3
)
CRUD Operation Using Stored Procedures in asp.net c#
How to Insert HTML Table Data and asp controls