Problem
When click next Button of EmployeeId i get error on line below :
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
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");
- }
- class="row">class="col-md-4">
- onclick="location.href='@Url.Action("Next", "Employees",new {id=Model.EmployeeId })'" style="display:inline">Next
- >
"ModelOnly" class="text-danger">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">
class="form-group">- "submit" value="Create" class="btn btn-default" />
Bryian TanPosted Jan 7, 2019, 7:37 PM
ahmed elbarbaryPosted Jan 7, 2019, 6:55 PM
Bryian TanPosted Jan 7, 2019, 4:05 PM
ahmed elbarbaryPosted Jan 7, 2019, 2:21 PM
Bryian TanPosted Jan 7, 2019, 1:38 PM