2017-07-05 57 views
0
routes.MapRoute( 
    name: "Default", 
    url: "{controller}/{action}/{id}", 
    defaults: new 
    { 
     controller = "ImageScan", 
     action = "ScanImage", 
     id = UrlParameter.Optional 
    }, 
    namespaces: new[] { "WebApplication3.Controllers" }); 

我得到的错误:MVC 5 routeconfig错误

HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

请求的URL:/Views/ImageScan/ScanImage.cshtml

回答

2

不要直接请求视图。您应该请求一个控制器操作,该操作可能会或可能不会返回相应的视图。

尝试

yourAppBaseAddress/ImageScan/ScanImage 

假设你没有任何其他的自定义路由definied覆盖默认路由公约,这将达到ImageScanControllerScanImage操作方法。如果此操作方法返回此视图,则应该能够看到此视图的代码执行结果。

public ActionResult ScanImage 
{ 
    return View(); 
} 

当行return View被执行,MVC框架将查找在~/Views/ImageScan~/Views/Shared目录称为ScanImage.cshtml视图。

+0

http:// localhost:64950/ImageScan/ScanImage 无法找到该资源。 描述:HTTP 404.您正在查找的资源(或其某个依赖项)可能已被删除,名称已更改或暂时不可用。请检查以下网址并确保它拼写正确。 请求的URL:/ ImageScan/ScanImage 的routeconfig被自动引导到以前的url..How使用合适的路由配置 –

+0

里面我Layout.cshtml我使用 @ Html.ActionLink( “应用程序名称”, “ImageScan” “ScanImage”,新的{area =“”},新的{@class =“navbar-brand”}) –

+0

删除'area'位。 – Amy