views:

303

answers:

1

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

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

clicking the above link would browse to:
http://apps.facebook.com/MyFBApplication/Home/Index/

"MyFBApplication" is the name of the facebook application. To build the link I started by calling

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

When a user click the link facebook will then make a request to this link under the covers:

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

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

As mentioned above facebook request the page data behind the scenes from.
http://www.myapplicationserver.com/facebook/123456/Home/Index/

The problem is a call to

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

will render a link that leads to
http://apps.facebook.com/facebook/123456/Home/Index/

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

I did get it work properly buy building a new set of extension methods.

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

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

Thanks!

+2  A: 

Why does this have a "smell"? Microsoft built the ActionLink methods as extension methods. If these do not serve your purposes, you can write your own just as you have done.

If you really wanted, I guess you could create your own version of the ActionLink method as an overload (as long as the method signatures aren't ambiguous).

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

Page Brooks
Okay maybe a custom ActionLink is not a bad solution I would just like to stay more mainstream.
Jamey McElveen
I used the action links they are working
Jamey McElveen