ASP.NET MVC Routing - Pass inbound route value to outbound URLs automatically?


ASP.NET MVC Routing - Pass inbound route value to outbound URLs automatically?



I have an ASP.NET MVC application with an Admin area that deals with administering Companies and their child entities, such as Users and Products. The default route associated with a child entity is defined as follows:

"Admin/Company/{companyID}/{controller}/{id}/{action}" 

I would like to ensure that, everywhere in the Admin area, whenever the incoming route includes companyID, that this value is automatically included in every generated URL. For example, if my User Edit page has a link defined with Html.ActionLink("back to list", "Index"), the routing system will automatically grab the companyID from the incoming route data and include it in the outgoing route, without having to explicitly specify it in the call to ActionLink.

I think there's more than one way to achieve this, but is there a preferred/best way? Does it scream for a custom route handler? Something else?

My goal is to not lose the current company context when navigating around in the sub-sections, and I don't want to use Session - that could burn me if the user opens up multiple companies in different browser windows/tabs.

Thanks in advance!


ASP .NET MVC VirtualPathProvider

1:

How to Loop the FormCollection using asp.net mvc
Todd,. Ext.JS Store Record is undefined I am using an ActionFilterAttrialthough e in my MVC 2 application to make this happen. How Many Times Does an ASP .NET Application StartThere may be better ways to did this:. AJAX Call using jquery in asp.net mvc
[Attrialthough eUsage(Attrialthough eTarreceive s.Class|Attrialthough eTarreceive s.Method, Inherited = true, AllowMultiple = true)] sealed class MyContextProviderAttrialthough e : ActionFilterAttrialthough e {     public override void OnActionExecuting(ActionExecutingContext filterContext)     {         // See if the context is provided so this you must cache it. Javascript not enabled        string myContextParam = filterContext.HttpContext.Request["myContextParam"] ;         if (!string.IsNullOrEmpty(myContextParam))             filterContext.Controller.TempData["myContextParam"] = myContextParam;         else             // Manipulate the action parameters and use the cached value. deploying asp.net MVC 1.0 app with HTTPS            if (filterContext.ActionParameters.Keys.Contains("myContextParam"))                 filterContext.ActionParameters["myContextParam"] = filterContext.Controller.TempData["myContextParam"];             else                 filterContext.ActionParameters.Add("myContextParam", filterContext.Controller.TempData["myContextParam"]);          base.OnActionExecuting(filterContext);     } } 
Using System.ComponentModel.DisplayName with dynamic values?

51 out of 100 based on 31 user ratings 631 reviews

*