asp.net-mvc-3 – MVC:为此对象定义的无参数构造函数
发布时间:2020-05-24 05:25:55 所属栏目:asp.Net 来源:互联网
导读:我有以下控制器定义 public class FeaturedAccommodationController : Controller{ ... public FeaturedAccommodationController(IAccommodationService accommodationService) { ... } public Actio
|
我有以下控制器定义 public class FeaturedAccommodationController : Controller
{
...
public FeaturedAccommodationController(IAccommodationService accommodationService)
{
...
}
public ActionResult Index(int page = 1)
{
...
}
...
}
我有一个链接,我用来调用这个索引操作方法 @Html.ActionLink("Featured Accommodations","Index","FeaturedAccommodation")
由于某些原因,当我点击这个链接我得到以下错误.这里有什么问题? 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,RuntimeMethodHandleInternal& ctor,Boolean& bNeedSecurityCheck) +0 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,Boolean skipCheckThis,Boolean fillCache) +98 System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly,Boolean skipVisibilityChecks,Boolean fillCache) +241 System.Activator.CreateInstance(Type type,Boolean nonPublic) +69 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext,Type controllerType) +67 [InvalidOperationException: An error occurred when trying to create a controller of type 'JattCore.UI.Admin.Controllers.FeaturedAccommodationController'. Make sure that the controller has a parameterless public constructor.] System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext,Type controllerType) +182 System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext,Type controllerType) +80 System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext,String controllerName) +74 System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext,IController& controller,IControllerFactory& factory) +232 System.Web.Mvc.<>c__DisplayClass6.<BeginProcessRequest>b__2() +49 System.Web.Mvc.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a() +13 System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Func`1 func) +124 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext,AsyncCallback callback,Object state) +98 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext,Object state) +50 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context,AsyncCallback cb,Object extraData) +16 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970356 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously) +184 解决方法创建控制器时,它在构造函数中需要一个称为IAccommodationService的参数.如果没有,则无法创建控制器. 解决问题的一个方法是使用依赖注入(DI)/控制反转(IoC),如ninject或类似的.如果你有一个,那么请记住注册IAccommodationService … (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 使用逗号分隔值搜索列
- .net – 对象数据源或代码隐藏:哪个更好?
- ASP.Net httpruntime executionTimeout不工作(而且debug =
- asp.net-mvc – 在BaseController中获取/设置HttpContext会
- asp.net-mvc – 如何在ASP.Net MVC 3中可选地呈现一个部分?
- ASP.net控件在实现资源时在代码背后找不到
- 如何在ASP.NET应用程序中使用jQuery捕获提交事件?
- asp.net-mvc – 谁设置HttpContext.User.Identity的IsAuthe
- 如何在ASP.NET中动态生成列表项到无序列表?
- jwt – ASP.NET 5 OAuthBearerAuthentication:以下认证方案
推荐文章
站长推荐
- asp.net – CookieAuthenticationOptions.Authen
- asp.net-mvc – 对MVC中的模型进行条件验证
- asp.net – 当用户关闭浏览器等待长时间运行的We
- asp.net-mvc – 你用ReSharper做什么?
- asp.net-mvc – ASP.NET MVC 5自定义错误页面
- asp.net-mvc – 添加MVC控件或视图时,Visual Stu
- asp.net-mvc – ASP.Net MVC中的线程安全性
- ASP.NET MVC表单和双字段
- asp.net-mvc – 使用ViewModels和对System.Web.M
- asp.net – 每个应用程序池的内存使用
热点阅读
