Routes mvc 4-如何将管线设置设置为正确,而不需要在浏览器中进行修复?

Routes mvc 4-如何将管线设置设置为正确,而不需要在浏览器中进行修复?,routes,Routes,我的路线是这样的: 公共类路由图 { 公共静态无效注册表项(路由收集路由) { routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”) 我的控制器名为“defaultPageController”,视图名为“defaultPage” 但当我打开页面时,我得到的url是: http://localhost:47983/Views/DefaultPage/DefaultPage.cshtml 然后我需要从url中删除“/view/”和“.cshtm

我的路线是这样的: 公共类路由图 { 公共静态无效注册表项(路由收集路由) { routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”)

我的控制器名为“defaultPageController”,视图名为“defaultPage”

但当我打开页面时,我得到的url是:

    http://localhost:47983/Views/DefaultPage/DefaultPage.cshtml
然后我需要从url中删除“/view/”和“.cshtml”,然后它就可以正常工作了

为什么会这样

我怎样才能改变它

tnx

MVC(模型-视图-控制器)就是这样,当您指示它在视图中以默认名称查找文件夹时,它会自动查找您的视图文件夹。但是如果您不想使用它,当然可以更改路由

using System.Web.Mvc;
using System.Web.Routing;
namespace MvcApplication1
{
    public class YourApplication : System.Web.YourApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                "YourName",                                           // Route name
                "Folder/{entryDate}",                            // URL with parameters
                new { controller = "Archive", action = "Entry" }  // Parameter defaults
            );
            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );
        }
        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }
}
记住也要在自定义路由下放置默认路由


还记得更换控制器

谢谢你的回答,我发现我做错了什么

问题是,我将视图页面设置为启动页面,然后项目只是试图跳过控件


我只需右键单击项目,然后单击属性,然后单击“web”,在那里我决定了要开始的默认url和路由。

controllername:defaultPageController小写,并且在路由中有{controller=“DefaultPage”用大写字母试着改变这个……这是一个书写错误,它们都以大写字母D开头。那么为了得到一个干净的url,我需要改变什么呢?
using System.Web.Mvc;
using System.Web.Routing;
namespace MvcApplication1
{
    public class YourApplication : System.Web.YourApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapRoute(
                "YourName",                                           // Route name
                "Folder/{entryDate}",                            // URL with parameters
                new { controller = "Archive", action = "Entry" }  // Parameter defaults
            );
            routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
            );
        }
        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }
}