System.MissingMethodException:没有为此对象定义的无参数构造函数

时间:2011-04-28 23:20:53

标签: asp.net-mvc-2 elmah

我有一个ELMAH控制器工厂这些使用ELMAH的步骤使得我不必在控制器中标记每个方法。该文件告诉我,当我明确地做

时,我没有无参数构造函数

PriceListController

public partial class PriceListController : Controller
{

    public PriceListController()
    {
    }


    [CanonicalUrlAttribute("PriceList")]
    [CompressionFilter(Order = 1)]
    [CacheFilter(Duration = 120, Order = 2)]
    public virtual ActionResult Index()
    {
        GodsCreationTaxidermyEntities context = new GodsCreationTaxidermyEntities();
        var viewModel = new PriceListViewModel() { PriceListAnimals = context.GetAnimalListForPriceList() };
        return View(viewModel);
    }


    [CompressionFilter(Order = 1)]
    [CacheFilter(Duration = 120, Order = 2)]
    public virtual ActionResult List(string animal)
    {
        GodsCreationTaxidermyEntities context = new GodsCreationTaxidermyEntities();

        var viewModel = new PriceListIndexViewModel() { AnimalPrices = context.GetPriceListByAnimal(animal) };
        return View(viewModel);
    }

}

ELMAHControllerFactory.cs

// <summary>
/// This custom controller factory injects a custom attribute 
/// on every action that is invoked by the controller
/// </summary>
public class ELMAHControllerFactory : DefaultControllerFactory
{
    /// <summary>
    /// Injects a custom attribute 
    /// on every action that is invoked by the controller
    /// </summary>
    /// <param name="requestContext">The request context</param>
    /// <param name="controllerName">The name of the controller</param>
    /// <returns>An instance of a controller</returns>
    public override IController CreateController(RequestContext requestContext, string controllerName)
    {
        var controller = base.CreateController(requestContext, controllerName);

        var c = controller as Controller;

        if (c != null)
            c.ActionInvoker = new ELMAHActionInvoker(new HandleErrorWithELMAHAttribute());

        return controller;
    }
}

我可能会误解,但我认为那里有一个无参数的构造函数,我错了吗?

1 个答案:

答案 0 :(得分:0)

这已经解决了,我删除了无参数构造函数并创建了一个新的构造函数,并且该错误消失了。