MVC 5 routeconfig错误 [英] MVC 5 routeconfig error

查看:63
本文介绍了MVC 5 routeconfig错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我得到了错误:

HTTP404.您正在寻找的资源(或其依赖项之一)可能已被删除,名称更改或暂时不可用.请查看以下URL,并确保其拼写正确.

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

Requested URL: /Views/ImageScan/ScanImage.cshtml

推荐答案

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

You do not request a view directly. You should request a controller action which may or may not return the corresponding view.

尝试

yourAppBaseAddress/ImageScan/ScanImage

假设您没有定义其他任何自定义路由来覆盖默认路由约定,则将单击 ImageScanController 中的 ScanImage 操作方法.如果此操作方法正在返回此视图,则应该能够看到该视图的代码执行的结果.

Assuming you do not have any other custom routing definied to override the default routing conventions, This will hit the ScanImage action method inside the ImageScanController. If this action method is returning this view, you should be able to see the result of this views' code executed.

public ActionResult ScanImage
{
   return View();
}

当执行 return View 行时,MVC框架将在〜/Views/ImageScan 〜/Views中查找名为ScanImage.cshtml的视图./Shared 目录.

When the line return View gets executed, the MVC framework will look for a view called ScanImage.cshtml in ~/Views/ImageScan and ~/Views/Shared directories.

这篇关于MVC 5 routeconfig错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆