-
Jan 7th, 2019, 12:28 AM
#1
Thread Starter
Lively Member
How to pass value of lastrecord from controller to view when click on last button
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
Code:
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>
-
Jan 7th, 2019, 01:04 AM
#2
Re: How to pass value of lastrecord from controller to view when click on last button
I don't really know what question you're asking.
-
Jan 7th, 2019, 07:06 AM
#3
Thread Starter
Lively Member
Re: How to pass value of lastrecord from controller to view when click on last button
Thank you for reply actually I have button name Last I need when click on it get last record for employee
so that what function i will write
and in whuch place action get or post
and whati write on view
can you help me in that please
-
Jan 7th, 2019, 07:15 AM
#4
Thread Starter
Lively Member
Re: How to pass value of lastrecord from controller to view when click on last button
Thank you for reply
actually I have button name Last I need when click on it get last record for employee table and show it
so that what function i will write to get last ?
and in which place action get or post i will put this
and what i write on view ?
can you help me in that please if possible
-
Jan 7th, 2019, 08:31 AM
#5
Re: How to pass value of lastrecord from controller to view when click on last button
You already know how to get the last record because you're already doing it. Put that code in an action and call that action from the Last button. That's all there is to it.
-
Jan 7th, 2019, 09:14 AM
#6
Thread Starter
Lively Member
Re: How to pass value of lastrecord from controller to view when click on last button
thank you for reply
how to call action from last button view if possible can you tell me
-
Jan 7th, 2019, 09:15 AM
#7
Thread Starter
Lively Member
Re: How to pass value of lastrecord from controller to view when click on last button
thank you for reply
how to call action from last button view if possible can you tell me
-
Jan 7th, 2019, 10:06 AM
#8
Re: How to pass value of lastrecord from controller to view when click on last button
What do you not understand about the information you found when you searched the web on that subject?
-
Aug 19th, 2019, 01:01 AM
#9
Member
Re: How to pass value of lastrecord from controller to view when click on last button
Try using onclick this way::
Code:
<div class="title_of_div">
<input type="button" value="Last" id="BtnLast" style="display: inline" onclick="location.href='@Url.Action("Action","Controller")'"/>
</div>
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|