Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# HTTP错误404.0-未找到-MVC映射路由_C#_Asp.net_Asp.net Mvc_Visual Studio - Fatal编程技术网

C# HTTP错误404.0-未找到-MVC映射路由

C# HTTP错误404.0-未找到-MVC映射路由,c#,asp.net,asp.net-mvc,visual-studio,C#,Asp.net,Asp.net Mvc,Visual Studio,我正在尝试为我的网站添加新视图,但我一直在“/”应用程序中获取错误服务器错误。我的视图链接到控制器,并且我的路由配置文件具有正确的路径 电影控制器 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.UI.WebControls; using Vidly.Models; namespace Vidly

我正在尝试为我的网站添加新视图,但我一直在“/”应用程序中获取错误服务器错误。我的视图链接到控制器,并且我的路由配置文件具有正确的路径

电影控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI.WebControls;
using Vidly.Models;

namespace Vidly.Controllers
{
    public class MovieController : Controller
    {
        // GET: Movie
        public ActionResult Random()
        {
            var movie = new Movie() {Name = "Shrek!",ID = 12};
            
            return View(movie);
            //return Content("Hello World!");
           // return HttpNotFound();
          // return RedirectToAction("Index", "Home", new {page = 1, sortBy = "name"});

        }

        public ActionResult ByDate(int year, byte month)
        {
                
            return Content(year + "/" + month);
        }
        
    }
}
RoutConfig.cs文件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Vidly
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "MoviesByReleaseDate",
                url: "movies/rel/{year}/{month}",
                defaults: new {controller = "Movies", action = "ByDate" },
                new {year = @"\d{4}", month =@"\d{2}"});

                routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

当我想访问
https://localhost:44352/movies/rel/2015/4
我收到
HTTP错误404.0-未找到

请显示您的rel操作。@Sergey我使用
路由解决了我的问题。mapmvcattributteroutes()
RouteConfig.cs
中添加
[Route(“movies/rel/{year}/{month}”)]
MovieController.cs
中是的,您试图在不启用属性配置的情况下实现属性路由@拉胡舒克拉:是的