开发者

Can't get new controllers or views to work in ASP.Net MVC

Basically what the title says. I created a new MVC application. I'm trying to add new pages to the site, but anytime I do I get the following error:

Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Products

Here is my controller, called ProductsController.

开发者_JAVA技巧
namespace MyAppMVC.Controllers
{
    public class ProductsController : Controller
    {
        public ActionResult Index()
        {
            return View("Index");
        }
    }
}

I had also tried

            return View();

But that didn't work.

My view is called Index.aspx, and it's in the folder Views/Products.

So everything looks fine to me, I looked in the NerdDinners tutorial and they don't seem to do anything different than me either. I've looked at the home controller that comes with the app, and mine seems identical. I'm pretty sure I don't have to add anything to the routing, but maybe I do.

Any ideas? This has got me stumped.

As per request here is my global.asax.cs file

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 = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

    }

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

        RegisterRoutes(RouteTable.Routes);
    }
}


Check your routing, using Phil Haack's route tester, and make sure your routes are properly routing to the desired controller methods.


The issue in the end was I had created an incorrect master page that had code behind files that were causing issues. I just failed to notice that MVC had it's own selection for Master Pages in the Add New dialogue. Oops!

Thanks for the help everyone.


It might be that you are using IIS6 and have not enabled a wildcard mapping. Or you could have also not set up the default document to Default.aspx? Or deleted Default.aspx from the application root? :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜