How to add functionality to buttons( Next previous first last) navigation buttons to primary key field using mvc
==========Problem==========
Cannot add functions to Next previous last first for create action using repository pattern based on EmployeeId field
==========Example==========
Employee Id : 5 as last record
IF create action view get loaded it must show max+1 for Employee Id meaning it will show 6
IF Click NextButton become 6
IF Click previousButton become 4 and get another data related as name age,etc...
IF Click LastButton become 5 and get another data related as name age,etc...
IF Click FirstButton become 1 and get another data related as name age,etc...
==========Details Code===========
I work in employee controller in action create
View action create have 4 buttons (First - Last - Next - Previous)
when create action loaded it will come with max number + 1 for EmployeeId
and after that using button previous next last first )
===========Employee Controller Have Create Action=====
- public class EmployeesController : Controller
- {
- private readonly IEmployees _context;
- public EmployeesController(IEmployees context)
- {
- _context = context;
- }
- // GET: Employees
- public async Task
Index() - {
- return View(await _context.GetAllAsyn());
- }
- // GET: Employees/Create
- public IActionResult Create()
- {
- How to call functions below
- // var maxId = maxid+1;
- getNext()
- getprevious()
- getlast()
- getfirst()
- return View();
- }
- ===============Generic Repository Pattern(required function I dont know======
- public class EFRepository
: IRepository classwhere T : - {
- protected TabDbContext _context { get; set; }
- public EFRepository(TabDbContext context)
- {
- _context = context;
- }
- getNext(){
- what implementation write
- }
- getprevious()
- {
- what implementation write
- }
- getlast()
- {
- what implementation write
- }
- getfirst()
- {
- what implementation write
- }
- public IQueryable
GetAll() - {
- return _context.Set
(); - }
- public virtual async Task
> GetAllAsyn() - {
- return await _context.Set
().ToListAsync(); - }
- public virtual T Get(int id)
- {
- return _context.Set
().Find(id); - }
- public virtual async Task
GetAsync( int id) - {
- return await _context.Set
().FindAsync(id); - }
- public virtual T Find(Expression
bool>> match) - {
- return _context.Set
().SingleOrDefault(match); - }
- public virtual async Task
FindAsync(Expression bool>> match) - {
- return await _context.Set
().SingleOrDefaultAsync(match); - }
- public ICollection
FindAll(Expression bool>> match) - {
- return _context.Set
().Where(match).ToList(); - }
- public async Task
> FindAllAsync(Expression bool>> match) - {
- return await _context.Set
().Where(match).ToListAsync(); - }
- }
- =====Buttons Navigation on Create View Of Employee Controller====
- class="title_of_div">
- style="display:inline">First
- style="display:inline">Next
- style="display: inline">Previous
- style="display: inline">Last
- view create controlls
- ===========Create Action Get==========
- >
- class="form-group">
- ="EmployeeId" class="control-label">
- for="EmployeeId" class="form-control" />
- for="EmployeeId" class="text-danger">
- class="form-group">
- ="BranchCode" class="control-label">
- for="BranchCode" class="form-control" />
- for="BranchCode" class="text-danger">
- class="form-group">
- ="EmployeeName" class="control-label">
- for="EmployeeName" class="form-control" />
- for="EmployeeName" class="text-danger">
Laxmidhar SahooPosted Jan 8, 2019, 12:58 AM
ahmed elbarbaryPosted Jan 7, 2019, 8:28 AM
Laxmidhar SahooPosted Jan 6, 2019, 10:41 PM