How can I change the way MVC renders an action link dynamically?

I need to change the way MVC renders action links (and form and url, etc.) based on a config setting. I am writing a facebook application using MS MVC and my action links need to render the link like so:

<a href="/MyFBApplication/Home/Index/">home</a>

      

by clicking on the link above go to:
http://apps.facebook.com/MyFBApplication/Home/Index/

"MyFBApplication" is the name of the facebook application. To create a link, I started by calling

Html.ActionLink("Home", "Index", "Home")

      

When a user clicks on a facebook link, they'll make a request for this link under the covers:

http://www.myapplicationserver.com/facebook/123456/Home/Index/
(123456 is client id and required).

The response from here is then processed by facebook and displayed to the user as:
http://apps.facebook.com/MyFBApplication/Home/Index/

As mentioned above, facebook is asking for page data behind the scenes.
http://www.myapplicationserver.com/facebook/123456/Home/Index/

The problem is calling

Html.ActionLink("Home", "Index", "Home")

      

will display a link that will lead to http://apps.facebook.com/facebook/123456/Home/Index/

and I need this to lead to:
http://apps.facebook.com/MyFBApplication/Home/Index/

I got it right to build a new set of extension methods.

 Html.FacebookActionLink("Home", "Index", "Home")
 Html.FacebookBeginForm("Index", "Home")
 Html.Facebook(etc)

      

But it has a "smell". I would like to find a place where I can intercept the Html.ActionLink () plumbing in the process and change the output. Then I can use all the standard calls.

Thanks!

+1


a source to share


1 answer


Why does it have a "smell"? Microsoft has developed ActionLink methods as extension methods. If they don't serve your purpose, you can write your own just like you do.

If you really wanted to, I think you could create your own version of the ActionLink method as an overload (as long as the method signatures are not ambiguous).



If you need to see how MS implemented the ActionLink extension method, check the source code in the LinkExtensions class. You can download it here .

+2


a source







All Articles