I created a new MVC 3 project. I ran the project and it loaded the home page. I then added a new view called “discussion.cshtml”.
I have 1 controller in the Controllers folder: HomeController
EDIT I misspelled Discussion before but it’s not misspelled in my project. the problem persists.
the new view is setup in this fashion: View -> Home -> Discussion.cshtml
I added this code to the HomeController
public ActionResult Discussion()
{
return View();
}
Problem: The view did not load when I hit run. I got the 404 error. The index page loads with this url “localhost:5553”. But I tried "localhost:5553/discussion.cshtml" and it can’t find it. How do I map/route to a view. I’m not sure what’s going on, I feel like I’m missing something simple.
The Global.ascx page has the usual default code if it helps:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace MvcApplication1
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
}
you can not do like localhost:5553/discussion.cshtml” on mvc.
right click over the Discussion action and select Add View.
if you browse
localhost:5553/Home/Discussion, that will route to the view you added above.