my asp.net mvc 2.0 application fails with error "No parameterless constructor defined for this objec

Posted by loviji on Stack Overflow See other posts from Stack Overflow or by loviji
Published on 2010-04-10T01:06:27Z Indexed on 2010/04/10 1:13 UTC
Read the original article Hit count: 2451

Filed under:

Hello, i'm new in asp.net mvc 2. I'm trying to list all data from one table(ms sql server table). as ORM I use Entity Framework. now, I'm tried to write something to do this:

Model:

private uqsEntities _uqsEntity;
public permissionRepository(uqsEntities uqsEntity)
{
    _uqsEntity = uqsEntity;
}
public IEnumerable<userPermissions> getAllData()
{
    return _uqsEntity.userPermissions;
}

controller:

    private DataManager _dataManager;

    public ManagePermissionsController(DataManager datamanager)
    {
        _dataManager = datamanager;

    }
    public ActionResult Index()
    {
        return RedirectToAction("List");
    }

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult List()
    {
        return List(null);
    }

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult List(int? userID)
    {

        return View(_dataManager.Permission.getAllData().ToList());
    }

Route:

   routes.MapRoute(
           "ManagePerm", // Route name
           "{controller}/{action}/{id}", // URL with parameters
           new { controller = "ManagePermissions", action = "Index"},
           new string[] { "uqs.Controllers" } // Parameter defaults
       );

and View automatically generated by Visual Studio(in action mouse right-click). when I run app. , my app. fails.

No parameterless constructor defined for this object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80

[InvalidOperationException: An error occurred when trying to create a controller of type 'uqs.Controllers.ManagePermissionsController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +190 System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +68 System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +118
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +46
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +63
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +13
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8679186 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

please, somebody, help me to catch problem.

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2