2011-04-28 75 views
0

我有一個ELMAH控制器factorym使用ELMAH的這些步驟使得它不需要在控制器中標記每個方法。該文件告訴我,我沒有參數的構造函數,而我清楚地做System.MissingMethodException:沒有爲此對象定義的無參數構造函數

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; 
    } 
} 

我可能會誤解,但我想有那裏沒有參數的構造函數,是我錯了嗎?

回答

0

這已解決,我刪除了無參數的構造函數並創建了一個新的錯誤消失了。

相關問題