Antarr Byrd
Antarr Byrd

Reputation: 26061

MVC3 debugger is failing

I'm trying to build a mvc3 application using VS 2010. But when every i try to debug it I get a 404 error. I can create a sharepoint site and the debugger works just fine. Below as a screenshot of some of the errors I'm getting.

enter image description here

UPDATE!

Global.ascx

using System.Web.Mvc;
using System.Web.Routing;

namespace afafda
{
    // 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);
        }
    }
}

HomeController

using System.Web.Mvc;

namespace afafda.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }

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

Upvotes: 0

Views: 235

Answers (1)

Peter
Peter

Reputation: 3956

You have to create at least the default controller, with the default action and the corresponding view.

The name of the default controller is set in your Global.asax.cs file:

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

In this example the default controller is "Home" and the default action "Index" (this are the defaults for a new MVC project in Visual Studio).

So you need to create a class "HomeController" in the directory "Controllers":

public class HomeController : System.Web.Mvc.Controller
{
    //
    // GET: /Home/

    public System.Web.Mvc.ActionResult Index()
    {
        return View();
    }

}

Then right-click on the View(); statement and click on "Create view..." (or similiar, im not sure what it is called in VS with english ui language).

Now you have a really basic MVC app, but I'd recommend you to start with one of the project templates shipped with MVC3 and work through a MVC3 tutorial. I think there should be plenty of them on the web.

Upvotes: 2

Related Questions