描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.MissingMethodException:没有为此对象定义无参数构造函数。
在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。
堆栈追踪:
[MissingMethodException:没有为此对象定义无参数构造函数。] System.RuntimeTypeHandle.CreateInstance(RuntimeType类型,Boolean publicOnly,Boolean noCheck,Boolean& canBeCached,RuntimeMethodHandleInternal& ctor,Boolean& bNeedSecurityCheck)+0 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,Boolean skipCheckThis,Boolean fillCache,StackCrawlMark& stackMark)+159 System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly,Boolean skipCheckThis,Boolean fillCache,StackCrawlMark& stackMark)+256 System.Activator.CreateInstance(Type type,Boolean nonPublic)+127 System.Activator.CreateInstance(类型类型)+11 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext,Type controllerType)+92
[InvalidOperationException:尝试创建类型' Web.Controllers.HomeController'的控制器时发生错误。确保控制器具有无参数的公共构造函数。] System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext,Type controllerType)+256 System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext,String controllerName)+81 Castle.Proxies.Invocations.IControllerFactory_CreateController.InvokeMethodOnTarget()+155 Castle.DynamicProxy.AbstractInvocation.Proceed()+116 Glimpse.Core.Extensibility.AlternateMethod.NewImplementation(IAlternateMethodContext context)+71 Castle.DynamicProxy.AbstractInvocation.Proceed()+604 Castle.Proxies.IControllerFactoryProxy.CreateController(RequestContext requestContext,String controllerName)+193 System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext,IController& controller,IControllerFactory& factory)+270 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext,AsyncCallback回调,对象状态)+86 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+ 12639055 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)+288
版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.18447
答案 0 :(得分:0)
将以下无参数构造函数添加到控制器:
public HomeController()
{
//...
}
在内部,MVC引擎(DefaultControllerActivator
)正在寻找这样的构造函数,以便实例化你的控制器。