Thursday, April 28, 2011

mvc2 resource not found, route issues, ajax calls resulting in 404

if you are having issues with a page being displayed in your MVC2 application here are a few things to check.
  • ensure that your controller has the WORD "Controller" before ".cs" extension.
  • this is crucial to accessing the controller.
  • Ensure your controller's class name has the word "Controller" at the end of the class name as well.    it should be the same as your filename minus the ".cs" extension
  • make sure you have your webmethod attirbute applied
    • eg. [HttpPost]
  • do NOT make your webmethod static.
  • if the above steps do not resolve your issue
    • add a reference to your web project to the RouteDebug.dll (you can find this in the iPortal directory in source control)
    • add this line your Global.asax.cs Application_Start method add the following line below the RegisterRoutes(RouteTable.Routes) method call
    • RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
    • open the page that is giving you the resource not found error
    • you should see your routes listed and the order they will be hit.  if a route that doesn't pertain to this page is hit before the route for this page, then you will need to either adjust the order of your routes in the Global.asax.cs file or change the path of the route.

No comments: