I'm not doing any fancy route patterns yet, just the basic controller, action, id style.
However, my actions never seem to be passed the id. When I stick a breakpoint in any one of my actions, the value of the id parameter is null. What gives?
Global.asax.cs:
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 = "Tenants", action = "Index", id = "" } // Defaults
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
//RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory());
}
protected void Application_AuthenticateRequest()
{
if (User != null)
Membership.GetUser(true);
}
}
Index() action on TenantsController.cs:
/// <summary>
/// Builds the Index view for Tenants
/// </summary>
/// <param name="tenantId">The id of a Tenant</param>
/// <returns>An ActionResult representing the Index view for Tenants</returns>
public ActionResult Index(int? tenantId)
{
//a single tenant instance, requested by id
//always returns a Tenant, even if its just a blank one
Tenant tenant = _TenantsRepository.GetTenant(tenantId);
//returns a list of TenantSummary
//gets every Tenant in the repository
List<TenantSummary> tenants = _TenantsRepository.TenantSummaries.ToList();
//bilds the ViewData to be returned with the View
CombinedTenantViewModel viewData = new CombinedTenantViewModel(tenant, tenants);
//return index View with ViewData
return View(viewData);
}
The value of the tenantId parameter is aways null!!! Argh! The silly part is that when I use Phil Haack's Route Debugger, I can clearly see that the debugger sees the id. What the crap?!