Friday, May 22, 2009

Html.ActionLink gotcha

For some reason I keep getting tripped up by the following sort of code: Seems simple enough but you end up with a link like : http://localhost:5825/ActionRule/Details?Length=10 Easy fix is to add a null parameter to the end of the list. Why? Well the compiler treats the first call as: Obviously the parameters are resolved incorrectly as there is no method signature such as: I really should write an extension method to cover this (fairly common for me) scenario. Who cares you say? Well to this point it seems that this is the only situation using ASP.Net MVC where I've had to add a null parameter on the end of a call to get the desired result. Not saying it's a bug...just interesting none the less.


  1. Nice tip, caught me out too!

  2. just ran into this :)

  3. Just ran into this too... I used

    Html.ActionLink("Text", "Action", new { controller = "Home", id = someParameter });

    instead... Not that pretty eaither