1
我嘗試使用VS2012編寫MVC 4中工作的代碼。在mvc 4和mvc 5中使用IController有什麼區別?
RouteConfig.cs
namespace MvcApplication2012
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "SayHello",
url: "hello",
defaults: new { controller = "hello" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
IController.cs
namespace MvcApplication2012.Controllers
{
public class HelloController : IController
{
public void Execute(System.Web.Routing.RequestContext requestContext)
{
requestContext.HttpContext.Response.Write("Hello, world!");
}
}
}
此代碼使用VS2012工作正常,在MVC 4,但使用VS2015在MVC 5不起作用。
什麼是偏差?爲什麼它不起作用?
返回錯誤 enter image description here