可访问性不一致:参数类型 [英] Inconsistent accessibility: parameter type

查看:85
本文介绍了可访问性不一致:参数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的控制器中出现此错误 -

不一致的可访问性:参数类型'CRUDApplication.Models.IEmployeeRepository'比方法'CRUDApplication.Controllers.EmployeeController.EmployeeController(CRUDApplication.Models.IEmployeeRepository)更难访问)'c:\users \Abhi \documents\visual studio 2013 \Projects\CRUDApplication\CRUDApplication\Controllers\EmployeeController.cs



这是我的代码:

使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Web;

使用System.Web.Mvc;

使用CRUDApplication.Models;

使用System.Data;



命名空间CRUDApplication.Controllers

{

公共类EmployeeController:Controller

{< br $>
//

//获取:/员工/



私有IEmployeeRepositor y _repository;



public EmployeeController()

:this(new EmployeeRepository())

{



}



公共EmployeeController(IEmployeeRepository存储库)

{

_repository = repository;

}



public ActionResult Index()

{

var employee = _repository.GetEmployee();

返回查看(员工);

}



public ActionResult Details(int id)

{

EmployeeModel model = _repository.GetEmployeeByID(id);

return View(model) ;

}



公共ActionResult创建()

{

返回查看(new EmployeeModel());

}



[Htt pPost]

公共ActionResult创建(EmployeeModel员工)

{

尝试

{

if(ModelState.IsValid)

{

_repository.InsertEmployee(employee);

返回RedirectToAction(Index);

}

}

catch(DataException)

{

ModelState.AddModelError( ,数据保存中的问题);

}

返回查看(员工);

}



public ActionResult Edit(int id)

{

EmployeeModel model = _repository.GetEmployeeByID(id);

返回查看(模型);

}



[HttpPost]

公共ActionResult编辑(EmployeeModel员工)

{

尝试

{

if(ModelState.IsValid)

{

_repository.UpdateEmployee(employee);

返回RedirectToAction(Index);

}

}

catch(DataException)

{

ModelState.AddModelError(,数据保存中的问题);

}

返回查看(员工);

}





公共ActionResult删除(int id,bool? saveChangesError)

{

if(saveChangesError.GetValueOrDefault())

{

ViewBag.ErrorMessage =问题在删除;

}

EmployeeModel employee = _repository.GetEmployeeByID(id);

return View(employee);

}



[HttpPost,ActionName(删除)]

public ActionResult DeleteConfirmed(int id)

{

尝试

{

EmployeeModel user = _repository.GetEmployeeByID(id);

_repository。 DeleteEmployee(id);

}

catch(DataException)

{



返回RedirectToAction(删除,

新的System.Web.Routing.RouteValueDictionary {

{id,id},

{saveChangesError,true}});

}

返回RedirectToAction(Index);

}



}

}



我尝试了很多东西,但仍然遇到同样的错误。如何解决它以及该错误意味着什么。

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.

推荐答案

感谢您的建议我自己解决了这个问题。



我做了什么 -

将IEmployeeRepository定义为Public

公共接口IEmployeeRepository {}

then

实现了它的接口方法,它被一个类继承。
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.


这篇关于可访问性不一致:参数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆