资源无法找到

时间:2013-02-13 21:08:15

标签: asp.net-mvc asp.net-mvc-3

我正在ASP.NET MVC3中创建一个网站。我的问题是,当引用的文件显示在正确的位置时,我收到“资源无法找到”错误。

这是确切的错误消息:

Server Error in '/' Application.
The resource cannot be found. 
Description: 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. 
Requested URL: /Views/Product/Index.cshtml

问题是,/ Views / Product中有一个Index.cshtml。

这是我的Global.asax的摘录:

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Product", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

分辨率: 问题是我通过右键单击并选择“设置为起始页面”将Index.cshtml设置为“起始页面”。根据nemesv的建议手动输入URL并看到一切正常后,我进入项目设置并将Web-> Start Action更改为“Current Page”。

1 个答案:

答案 0 :(得分:1)

您要求/Views/Product/Index.cshtml,这是错误的。您必须使用ProductController方法创建Index课程:

public class ProductController : Controller
{
    public void Index()
    {
        return View();
    }
}

然后请求localhost:yourport/获取您在路线中定义的产品控制器的索引(或仅/Product/Index)。