I’ll try to explain in as much detail as possible my setup.
1) I’m using an Area (MVC 4). Here’s the folder and file setup:

2) I’m resolving by default straight to my Area (not a Home controller in the root views) on purpose (I don’t really need the Home controller that’s not related to this question, just some background info)
3) My global.asax registration of routes looks like this:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
4) My route.config looks like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Purposely not going to use the Home Controller (just a convention I want in place)
routes.MapRoute("Default", "", new { area = "Search", controller = "Member", action = "Index", id = UrlParameter.Optional }).DataTokens.Add("area", "Search");
}
5) My area’s registration routing looks like this:
public class MemberAreaRegistration : AreaRegistration
{
public override string AreaName
{
get { return "Search"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute("Search_Member_GetMemberByContractNumber", "Search/Member/{id}", defaults: new { controller = "Member", action = "GetMemberByContractNumber", id = UrlParameter.Optional });
context.MapRoute("Search_Default", "Search/{controller}/{action}/{id}", defaults: new { controller = "Member", action = "Index", id=UrlParameter.Optional});
}
}
6) I have a controller with this action:
[HttpGet]
public JsonResult GetMemberByContractNumber(int contractNumber)
{
Member memberDto = MemberCRUD.RetrieveMember(contractNumber);
JsonResult member = Json(memberDto, JsonRequestBehavior.AllowGet);
Json(JsonConvert.SerializeObject(member));
return member;
}
7) I have a view that’s trying to send an ajax request to that action:
// Get the results & Bind to grid
$(function () {
var members = [];
$.getJSON('Search/Member/26049', function (data) {
members = data;
grid = new Slick.Grid("#searchResults-Grid", members, columns, options);
});
});
What works: I can run the site, it hits my Member’s Index() action and loads the Member’s Index View. That’s not the problem here.
What the problem is: I can’t get this to resolve…it doesn’t find my controller and action in the jQuery getJSON request ‘Search/Member/26049’
** The error I get in FireBug**:
http://localhost/OurappName/Search/Member/26049 404 Not Found
19ms
in the response:
<b> Requested URL: </b>/ballysearch/Search/Member/26049<br><br>
What I’ve Tried: Originally in my area’s route config, I had that first line at the end so tried moving it up. I’m talking about the context.MapRoute(“Search_Member_GetMemberByContractNumber”, “Search/Member/{id}”..I had that after my default route. Then switched up cause I figured it’s always going to obviously hit my default route..which should really just be a “catch-all” route at the end in this case instead.
I have tried several variations of the url from the getJSON such as:
‘Member/26049’
I’m pretty sure my controller’s action is fine the way it’s setup.
I know it’s probably a route issue but I do not see what it is.
UPDATE:
here’s the route debug results

UPDATE:
Looks now like maybe I was thinking all along it was a route issue but at least now it’s ok so not sure what this error means by “Resource”
Here’s the routes I have now that seem to be working in my MemberAreaRegistration.cs

context.MapRoute(“Search_Member”, “Search/Member/{contractNumber}”, new { controller = “Member”, action = “GetMemberByContractNumber”, contractNumber = UrlParameter.Optional });
context.MapRoute(“Search_Default”, “Search/{controller}/{action}/{id}”, new {controller=”Member”, action = “Index”, id = UrlParameter.Optional });
now not sure why I’m getting this resource error. In Firebug, there’s some additional info but I still don’t get what’s wrong with my controller code if that’s the case or my jQuery code if that’s also an issue…I don’t see it:
[HttpException]: The controller for path '/OurAppName/Search/Member/1234' was not found or does not implement IController.
Couple more views of the error from firebug still:


UPDATE ——————————————- 10/27/2012:
Want to post my current attempt detailed info to this point
My routes are setup like this in my Route.Config:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("favicon.ico");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(css|js|gif|jpg)(/.*)?" });
routes.IgnoreRoute("{*robotstxt}", new { robotstxt = @"(.*/)?robots.txt(/.*)?" });
// Purposely not going to use the Home Controller, we don't need it so hence the DataTokens to tell MVC to go straight to my Area called Search to look for the member controller for the default route when you first hit the View
routes.MapRoute("Default", "", new { area = "Search", controller = "Member", action = "Index", id = UrlParameter.Optional }).DataTokens.Add("area", "Search");
}
My Area’s registration routes:
namespace OurApp.Web.Areas.Search.Views.Member
{
public class MemberAreaRegistration : AreaRegistration
{
public override string AreaName
{
get { return "Search"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute("Search_Member", "Search/Member/{contractNumber}", new { controller = "Member", action = "GetMemberByContractNumber", contractNumber = UrlParameter.Optional });
context.MapRoute("Search_Default", "Search/{controller}/{action}/{id}", new {controller="Member", action = "Index", id = UrlParameter.Optional });
}
}
}
Finally my entire Controller Code:
namespace OurApp.Web.Areas.Search.Controllers
{
public class MemberController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpGet]
public JsonResult GetMemberByContractNumber(int contractNumber)
{
Member memberDto = MemberCRUD.RetrieveMember(contractNumber);
JsonResult member = Json(memberDto, JsonRequestBehavior.AllowGet);
return Json(member, JsonRequestBehavior.AllowGet);
return member;
}
[HttpGet]
public ActionResult TestTheRoute(int daveIdTest)
{
return null;
}
}
}
1) I have no begin form tag in my View. That’s because I’m only trying to just test this $.ajax() function out and later I’ll add a form and invoke that call from some event. So that should not matter, that I don’t have a form element yet right? I simply have $.ajax call at the top of my view in the open so it fires off on its own.
2) It seems like it’s hitting my routes ok as you can see above. I just wonder if it’s how I’m forming my $.ajax() call in terms of the callback and maybe related to, my controller method is not fully correct? I’m returning json from my action but it’s ok to have how I have it I assume. I don’t know, unless I can try something different in my action method that’s returning the json. I don’t know if my $.ajax call needs to specify the return type expected in the callback now that I just thought about it as I am typing this but I’ll check that also.
for example when I setup the $.ajax call like this (see below), I’m getting a response back so I think that tells me IIS is able to send a response after it hit my route and controller ok. So I’m thinking it’s my action method that’s not returning a correct json object, not really sure but at this point, if the route debugger from Phil Haack shows it’s definitely hitting my routes, then it can’t be that…the ajax call IS hitting my route.
$.ajax({
url: 'OurApp/Search/Member/26049',
type: "GET",
dataType: "json",
success: function (response)
{
alert('we got a mother fing response!');
grid = new Slick.Grid("#memberSearchResults-Grid", response.data, columns, options);
},
error: function (e) { alert('response error: '); }
});
so I get the alert for the error case above, it’s hitting this. I don’t know if I will always get a response…probably I assume IIS would respond in a failed request AND successful route request…?
I tried to attach to the worker process and then refresh the page after setting a debug point on the first line of that action method that’s returning json in my controller but that line is never hit. I don’t know why. I can’t get any debug points hit, not
Here’s the request header from firebug just for additional info:
GET http://localhost/OurApp/Search/Member/26049 HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Proxy-Connection: keep-alive
Here’s some of the resopnse and what’s interesting is even though it shows my route is being hit on my controller, this error says no, it isn’t hitting your controller so I’m so dumbfounded at this point on wtf is going on and where:
HeadersResponseCacheHTML
The resource cannot be found.
body {font-family:”Verdana”;font-weight:normal;font-size: .7em;color:black;}
p {font-family:”Verdana”;font-weight:normal;color:black;margin-top: -5px}
b {font-family:”Verdana”;font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:”Verdana”;font-weight:normal;font-size:18pt;color:red }
H2 { font-family:”Verdana”;font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:”Lucida Console”;font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
<body bgcolor="white">
<span><H1>Server Error in '/OurApp' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>The resource cannot be found.</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>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.
<br><br>
<b> Requested URL: </b>/OurApp/Search/Member/26049<br><br>
<hr width=100% size=1 color=silver>
<b>Version Information:</b> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
</font>
</body>
and related mvc route debugger result for this request:

what gets me is that it shows “The controller for path '/OurApp/Search/Member/26049; was not found or does not implement IController.” But if the route debug is saying it is being hit, wtf? I’m so lost. Also again I can’t debug it so that tells me it ISN’T hitting my controller or controller action.
it’s always something stupid right? I debugged or was able to debug finally, stepped through. Saw nothing but then I noticed that the namespace for my MemberAreaRegistration was placed in my Views folder within my Area. I moved it out to the root of Area/Search and now it seems to be finding my controller as the namespace now changed to Areas.Search