Click here to Skip to main content
15,886,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am getting this error in my contoller-
Inconsistent accessibility: parameter type 'CRUDApplication.Models.IEmployeeRepository' is less accessible than method 'CRUDApplication.Controllers.EmployeeController.EmployeeController(CRUDApplication.Models.IEmployeeRepository)' c:\users\Abhi\documents\visual studio 2013\Projects\CRUDApplication\CRUDApplication\Controllers\EmployeeController.cs

Here's my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CRUDApplication.Models;
using System.Data;

namespace CRUDApplication.Controllers
{
public class EmployeeController : Controller
{
//
// GET: /Employee/

private IEmployeeRepository _repository;

public EmployeeController()
: this(new EmployeeRepository())
{

}

public EmployeeController(IEmployeeRepository repository)
{
_repository = repository;
}

public ActionResult Index()
{
var employee = _repository.GetEmployee();
return View(employee);
}

public ActionResult Details(int id)
{
EmployeeModel model = _repository.GetEmployeeByID(id);
return View(model);
}

public ActionResult Create()
{
return View(new EmployeeModel());
}

[HttpPost]
public ActionResult Create(EmployeeModel employee)
{
try
{
if (ModelState.IsValid)
{
_repository.InsertEmployee(employee);
return RedirectToAction("Index");
}
}
catch (DataException)
{
ModelState.AddModelError("", "Problem in Data Saving");
}
return View(employee);
}

public ActionResult Edit(int id)
{
EmployeeModel model = _repository.GetEmployeeByID(id);
return View(model);
}

[HttpPost]
public ActionResult Edit(EmployeeModel employee)
{
try
{
if (ModelState.IsValid)
{
_repository.UpdateEmployee(employee);
return RedirectToAction("Index");
}
}
catch (DataException)
{
ModelState.AddModelError("", "Problem in Data Saving");
}
return View(employee);
}


public ActionResult Delete(int id, bool? saveChangesError)
{
if (saveChangesError.GetValueOrDefault())
{
ViewBag.ErrorMessage = "Problem in Deleting";
}
EmployeeModel employee = _repository.GetEmployeeByID(id);
return View(employee);
}

[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)
{
try
{
EmployeeModel user = _repository.GetEmployeeByID(id);
_repository.DeleteEmployee(id);
}
catch (DataException)
{

return RedirectToAction("Delete",
new System.Web.Routing.RouteValueDictionary {
{ "id", id },
{ "saveChangesError", true } });
}
return RedirectToAction("Index");
}

}
}

I tried many things but still gettng same error. How to resolve it and what does that error mean.
Posted
Comments
[no name] 26-Aug-14 7:34am    
It means to go check your access modifiers.
Abhishek Jaiswall 26-Aug-14 7:52am    
I tried and defined IEmployeeRepository as public but still not working.
Nathan Minier 26-Aug-14 8:30am    
What about the class that's fulfilling the property injection?
Abhishek Jaiswall 26-Aug-14 9:05am    
Thanks for your kind reply buddy, but i have solved it my own.

1 solution

Thank You for your suggestion guys I have solved it my own.

What i did-
defined IEmployeeRepository as Public
Public interface IEmployeeRepository {}
then
implemented Interface method for it, where it was getting inherited by a class.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900