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
277.8k
How to add functionality to buttons( Next previous first las
Jan 6 2019 2:45 PM
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<IActionResult> 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<T> : IRepository<T> where T :
class
{
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<T> GetAll()
{
return
_context.Set<T>();
}
public
virtual
async Task<ICollection<T>> GetAllAsyn()
{
return
await _context.Set<T>().ToListAsync();
}
public
virtual
T Get(
int
id)
{
return
_context.Set<T>().Find(id);
}
public
virtual
async Task<T> GetAsync(
int
id)
{
return
await _context.Set<T>().FindAsync(id);
}
public
virtual
T Find(Expression<Func<T,
bool
>> match)
{
return
_context.Set<T>().SingleOrDefault(match);
}
public
virtual
async Task<T> FindAsync(Expression<Func<T,
bool
>> match)
{
return
await _context.Set<T>().SingleOrDefaultAsync(match);
}
public
ICollection<T> FindAll(Expression<Func<T,
bool
>> match)
{
return
_context.Set<T>().Where(match).ToList();
}
public
async Task<ICollection<T>> FindAllAsync(Expression<Func<T,
bool
>> match)
{
return
await _context.Set<T>().Where(match).ToListAsync();
}
}
=====Buttons Navigation on Create View Of Employee Controller====
<div
class
=
"title_of_div"
>
<button id=
"BtnFirst"
style=
"display:inline"
><b>First</b></button>
<button id=
"BtnNext"
style=
"display:inline"
><b>Next</b></button>
<button id=
"BtnPrevious"
style=
"display: inline"
><b>Previous</b></button>
<button id=
"BtnLast"
style=
"display: inline"
><b>Last</b></button>
</div>
view create controlls
===========Create Action Get==========
<form asp-action=
"Create"
>
<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
=
"BranchCode"
class
=
"control-label"
></label>
<input asp-
for
=
"BranchCode"
class
=
"form-control"
/>
<span asp-validation-
for
=
"BranchCode"
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>
</form>
</div>
</div>
============Model related data=============
public
class
Employee
{
[Key]
public
int
EmployeeId {
get
;
set
; }
public
int
BranchCode {
get
;
set
; }
public
string
EmployeeName {
get
;
set
; }
}
=======technology Used============
I work in visual studio 2017 asp.net core 2.1 sql server 2012 using repository pattern generic
Reply
Answers (
3
)
jqgrid cascading drop down option values in add box
How to use save button to make save in both cases insert and