0

我正在从事从 Asp.net MVC4 beta 到 Asp.net MVC4 的迁移工作,但是我遇到了缺少 dll 引用的问题。请帮我 。

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = System.Web.Http.RouteParameter.Optional }
            );


            routes.MapRoute(
               name: "Default",
               url: "{controller}/{action}/{id}",
               defaults: new { controller = "Login", action = "Login", id = UrlParameter.Optional }
           );
        }

上面的代码无法编译成功,Visual Studio 说System.Web.Routing.RouteCollection' does not contain a definition for 'MapHttpRoute' and no extension method 'MapHttpRoute' accepting a first argument of type 'System.Web.Routing.RouteCollection' could be found (are you missing a using directive or an assembly reference?)

更重要的是这种问题经常发生。因为这几天Asp.net MVC的版本变化太频繁了。Windows Azure Client ApI 的版本也是如此。这是一个非常烦人的问题。我希望有人能就如何处理它提供一些建议。谢谢。

4

3 回答 3

3

我通过在 RouteConfig.cs 中添加对 System.Web.Http 的引用来解决它。

于 2012-12-17T06:29:24.190 回答
3

我遇到了同样的问题,但无法通过添加对 System.Web.Http 的引用来解决它。我仍然收到同样的错误:System.Web.Routing.RouteCollection' does not contain a definition for 'MapHttpRoute'

I believe this is occurring because in the latest version of MVC4, MapHttpRoute is no longer supported.

As it turned out, the function MapRoute is identical in parameter construction. If you replace MapHttpRoute with MapRoute, you should be able to compile your code and move onwards.

于 2013-11-05T01:08:08.827 回答
0

I solved this by adding a reference to System.Web.Mvc.Html and System.Web.Mvc in the web.config.

  <system.web>
    ...
    <httpRuntime targetFramework="4.5.2"/>
        <pages>
            <namespaces>
                <add namespace="System.Web.Mvc" />
                <add namespace="System.Web.Mvc.Html" />
            </namespaces>
        </pages>
    ...
  </system.web>
于 2016-11-02T17:45:34.867 回答