using Michell.ClaimsAuditAdmin.Models;
using Mitchell.ClaimsAuditAdmin.Repositories;
using Mitchell.ClaimsAuditAdmin.Web.Models;
using System.Web.Mvc;
namespace Mitchell.ClaimsAuditAdmin.Web.Controllers
{
public class ClaimAuditAdminController : Controller
{
private readonly IClaimsAuditAdminRepository claimAuditAdminRepository;
public ClaimAuditAdminController(IClaimsAuditAdminRepository claimAuditAdminRepository)
{
this.claimAuditAdminRepository = claimAuditAdminRepository;
}
public ActionResult Index()
{
return View("SearchResultTest");
}
public ActionResult TestView()
{
return View("TestView");
}
public ViewResult DisplayClaimAuditView()
{
return View("_ClaimAuditAdminView");
}
public ActionResult SearchResultTest()
{
return View();
}
public ActionResult ClaimAuditReviewFilter()
{
//ClaimAuditModel objClaimAudit = new ClaimAuditModel();
//objClaimAudit.ClaimAudit_ID = 1;
//objClaimAudit.ClaimAudit_Name = "Claim1";
//objClaimAudit.FromDate = DateTime.Now.AddYears(-1);
//objClaimAudit.FromDate = DateTime.Now;
return PartialView("_ClaimAuditAdminView");
}
}
}
我知道这个问题已被多次询问,但在阅读了所有那些类似的问题后,我无法跟踪我的错误。我已将调试器放在我的控制器的构造函数(ClaimAuditAdminController)中,但调试器不会去那里。 我的 Route.Config 是
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "ClaimAuditAdmin", action = "DisplayClaimAuditView", id = UrlParameter.Optional }
);
}
我错误的屏幕截图是
异常详细信息:System.MissingMethodException:无参数 为此对象定义的构造函数。
来源错误:
执行期间生成了未处理的异常 当前的网络请求。有关的来源和位置的信息 可以使用下面的异常堆栈跟踪来识别异常。
堆栈追踪:
[MissingMethodException:没有为此定义无参数构造函数 对象。] System.RuntimeTypeHandle.CreateInstance(RuntimeType类型, Boolean publicOnly,Boolean noCheck,Boolean& canBeCached, RuntimeMethodHandleInternal&安培; ctor,布尔& bNeedSecurityCheck)+0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,Boolean skipCheckThis,Boolean fillCache,StackCrawlMark& stackMark)+113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis,Boolean fillCache,StackCrawlMark& stackMark) +232 System.Activator.CreateInstance(Type type,Boolean nonPublic)+83 System.Activator.CreateInstance(Type type)+6 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext,Type controllerType)+55[InvalidOperationException:尝试创建时出错 控制器类型 'Mitchell.ClaimsAuditAdmin.Web.Controllers.ClaimAuditAdminController'。 确保控制器具有无参数的公共构造函数。] System.Web.Mvc.DefaultControllerActivator.Create(的RequestContext requestContext,Type controllerType)+179
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&控制器,IControllerFactory&厂) +197 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext,AsyncCallback回调,对象状态)+49
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback回调,对象状态)+50
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext的 context,AsyncCallback cb,Object extraData)+16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301 System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)+155----------------------------------------------- ---------------------------------版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.17929 }
答案 0 :(得分:1)
激活器尝试使用无参数构造函数创建ur控制器。但是你的控制器构造函数有参数
public ClaimAuditAdminController(IClaimsAuditAdminRepository claimAuditAdminRepository) <--this place
{
this.claimAuditAdminRepository = claimAuditAdminRepository;
}
发生异常。 尝试从构造函数中删除param或尝试覆盖DefaultControllerFactory 并使用参数创建控制器。
看here