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
中是的,您试图在不启用属性配置的情况下实现属性路由@拉胡舒克拉:是的