HTTP Error 404.0 – Not Found – MVC Map Routing

  Uncategorised

I’m trying to add a new view for my website however I keep on getting the error Server Error in ‘/’ Application.My view is linked to the controller and my route config file has the right the path.

Movie Controller

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 file

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 [email protected]"d{2}"});

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

Well when i want to access to https://localhost:44352/movies/rel/2015/4 I’m getting HTTP Error 404.0 - Not Found

Source: Visual Studio Questions

LEAVE A COMMENT