2

我的错误HelpController

HelpController 类型的构造函数包含名为“config”的参数和未注册的类型 HttpConfiguration。请确保 HttpConfiguration 已注册,或更改 HelpController 的构造函数。

有没有其他方法可以解决这个问题,因为我曾经Configuration得到Configuration.GetModelDescriptionGenerator();

public class HelpController : Controller
{
    private const string ErrorViewName = "Error";

    public HelpController(HttpConfiguration config)
    {
        Configuration = config;
    }

    public HttpConfiguration Configuration { get; private set; }

    ...

    public ActionResult ResourceModel(string modelName)
    {
        if (!String.IsNullOrEmpty(modelName))
        {
            ModelDescriptionGenerator modelDescriptionGenerator = Configuration.GetModelDescriptionGenerator();
            ModelDescription modelDescription;
            if (modelDescriptionGenerator.GeneratedModels.TryGetValue(modelName, out modelDescription))
            {
                return View(modelDescription);
            }
        }

        return View(ErrorViewName);
    }
}
4

1 回答 1

2

将您的构造函数更改为private并放回由 VS 生成的无参数构造函数。你HelpController应该看起来像这样。

public class HelpController : Controller
{
    private const string ErrorViewName = "Error";

    public HelpController()
        : this(GlobalConfiguration.Configuration)
    {
    }

    private HelpController(HttpConfiguration config)
    {
        Configuration = config;
    }


    public HttpConfiguration Configuration { get; private set; }
}
于 2017-03-29T09:24:26.283 回答