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.9k
When click next Button get error NullReferenceException
Jan 7 2019 12:22 PM
Problem
When click next Button of EmployeeId i get error on line below :
<button id=
"BtnNext"
onclick=
"location.href='@Url.Action("
Next
", "
Employees
",new {id=Model.EmployeeId })'"
style=
"display:inline"
><b>Next</b></button>
NullReferenceException: Object reference not set to an instance of an object.
the line error found on view create of action create of Employees Controller .
Details
I have Employees controller have action Create and his view Create
ON View Create I put button Next to show next Row EmployeeId,EmployeeName,etc
but it show error above
Next button it must when click on it show next record and related data if exist
technology used asp.net core 2.1 visual studio 2017 sql server 2012
Employee Controller Code
public
class
EmployeesController : Controller
{
private
readonly
IEmployees _context;
public
EmployeesController(IEmployees context)
{
_context = context;
}
public
IActionResult Create()
{
return
View(model);
}
[HttpPost]
[ValidateAntiForgeryToken]
public
async Task<IActionResult> Create(Employee employee)
{
return
View(employee);
}
public
ActionResult Next(
int
id)
{
var nextID = _context.GetAll().OrderBy(i => i.EmployeeId)
.SkipWhile(i => i.EmployeeId != id)
.Skip(1)
.Select(i => i.EmployeeId);
ViewBag.NextID = nextID;
return
View(
"Create"
);
}
<div
class
=
"row"
>
<div
class
=
"col-md-4"
>
<button id=
"BtnNext"
onclick=
"location.href='@Url.Action("
Next
", "
Employees
",new {id=Model.EmployeeId })'"
style=
"display:inline"
><b>Next</b></button>
<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
=
"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>
<div
class
=
"form-group"
>
<input type=
"submit"
value=
"Create"
class
=
"btn btn-default"
/>
</div>
</form>
</div>
</div>
Reply
Answers (
5
)
how to integrate paypal gateway to my asp.net web api app
session variables-null/lost - IIS after 20-30 secs when idle