ahmed elbarbary

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
  1. public IActionResult Create()  
  2. {  
  3. var results = _context.GetAll().OrderBy(Employee => Employee.EmployeeId).LastOrDefault();  
  4. return View();  
  5. }  
  6. [HttpPost]  
  7. [ValidateAntiForgeryToken]  
  8. public async Task<IActionResult> Create(Employee employee)  
  9. {  
  10. }  
on view create
  1. <div class="title_of_div">  
  2. <button id="BtnLast" style="display: inline"><b>Last</b></button>  
  3. </div>  
  4. <div class="row">  
  5. <div class="col-md-4">  
  6. <form asp-action="Create">  
  7. <div asp-validation-summary="ModelOnly" class="text-danger"></div>  
  8. <div class="form-group">  
  9. <label asp-for="EmployeeId" class="control-label"></label>  
  10. <input asp-for="EmployeeId" class="form-control" />  
  11. <span asp-validation-for="EmployeeId" class="text-danger"></span>  
  12. </div>  
  13. <div class="form-group">  
  14. <label asp-for="EmployeeName" class="control-label"></label>  
  15. <input asp-for="EmployeeName" class="form-control" />  
  16. <span asp-validation-for="EmployeeName" class="text-danger"></span>  
  17. </div>  
  18. <div class="form-group">  
  19. <label asp-for="EmployeeAge" class="control-label"></label>  
  20. <input asp-for="EmployeeAge" class="form-control" />  
  21. <span asp-validation-for="EmployeeAge" class="text-danger"></span>  
  22. </div>  
  23. <div class="form-group">  
  24. <input type="submit" value="Create" class="btn btn-default" />  
  25. </div>  
  26. </form>  
  27. </div>  
  28. </div>  
technology used asp.net core 2.1 visual studio 2017 sql server 2012

Answers (3)