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>
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.
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
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
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.
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
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
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?
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>