为了账号安全,请及时绑定邮箱和手机立即绑定

ASP.NET MVC:没有为此对象定义的无参数构造函数

ASP.NET MVC:没有为此对象定义的无参数构造函数

ASP.NET MVC:没有为此对象定义的无参数构造函数Server Error in '/' Application.--------------------------------------------------------------------------------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: Line 16:             HttpContext.Current.RewritePath(Request.ApplicationPath, false);Line 17:             IHttpHandler httpHandler = new MvcHttpHandler();Line 18:             httpHandler.ProcessRequest(HttpContext.Current);Line 19:             HttpContext.Current.RewritePath(originalPath, false);Line 20:         }我正在关注Steven Sanderson的“ Pro ASP.NET MVC框架 ”一书。在页132,根据作者的建议,我下载了ASP.NET MVC Futures程序集,并将其添加到我的MVC项目中。[注意:这可能是一个红鲱鱼。]在此之后,我无法再加载我的项目。上面的错误阻止了我。我的问题不是,“你能帮我解决一下我的代码吗?”相反,我想更全面地了解:我该如何解决这个问题?我应该寻找什么?根本原因是什么?看起来我应该比现在更深入地了解路由和控制器。
查看完整描述

3 回答

?
慕勒3428872

TA贡献1848条经验 获得超6个赞

我刚遇到类似的问题。当a Model没有无参数构造函数时,会发生相同的异常。

调用堆栈正在计算一个负责创建模型新实例的方法。

System.Web.Mvc.DefaultModelBinder。CreateModel(ControllerContext controllerContext,ModelBindingContext bindingContext,Type modelType)


这是一个示例:

public class MyController : Controller{
    public ActionResult Action(MyModel model)
    {

    }}public class MyModel{
    public MyModel(IHelper helper) // MVC cannot call that
    {
        // ...
    }

    public MyModel() // MVC can call that
    {
    }}


查看完整回答
反对 回复 2019-08-08
?
牧羊人nacy

TA贡献1862条经验 获得超7个赞

您需要与控制器对应的操作没有参数。

看起来你有控制器/动作组合:

public ActionResult Action(int parameter){}

但你需要

public ActionResult Action(){}

另外,查看Phil Haack的Route Debugger来排除路由故障。


查看完整回答
反对 回复 2019-08-08
  • 3 回答
  • 0 关注
  • 1583 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信