开发者

mvc 2 - 404 error page not found

开发者 https://www.devze.com 2023-04-08 14:09 出处:网络
I am getting a 404 error when I start up my mvc 2 project. I followed the guide here: http://net.tutsplus.com/tutorials/asp-net/asp-net-from-scratch-mvc/

I am getting a 404 error when I start up my mvc 2 project. I followed the guide here: http://net.tutsplus.com/tutorials/asp-net/asp-net-from-scratch-mvc/

I haven't set up a start page (Which I figured out to be a normal newbie mistake) and I've edited my global.asax class to look like below so it contains the right route. I just can't figure out why it gives me a 404.

public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "CreateUserController", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
        }
    }

Here's my CreateUserController:

public class CreateUserController : Controller
    {
        //
        // GET: /CreateUser/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult AddLinks()
        {
            return View();
        }

    }

My Project looks like this:

  • Controllers
    • CreateUserController.cs
  • Models ((This is empty for now))
  • Views
    • CreateUser
      • Index.aspx
    • Shared
      • Site.Master
  • global.asax
  • Web.Config

I am to开发者_运维知识库tally new at mvc 2, I've worked with normal web forms for about 2 months now. Let me know if you need the aspx files, but I just need it to find my controller, at this point I just want another error.


routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "CreateUser", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

controller should be "CreateUser" not "CreateUserController"

you can see this hint in your file

        // GET: /CreateUser/
0

精彩评论

暂无评论...
验证码 换一张
取 消