I found the same problem as you. Also, I was surprised that it's hard to find simple solution for that in the internet.
There is my solution:
You can note that if you call @Url.Action with route values, e.g. @Url.Action( "TagChange", new { id = 1 } ); then it will work ok. But of course, we don't want to pass fake void route values. So, let's just add another
map route to Global.asax, for example:
routes.MapRoute("Simple",
"{controller}/{action}",
new { controller = "Home", action = "Index" });
routes.MapRoute("Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
It's look like the issue that it requires route values even if they are declared as optional. So let's just add new map route (as shown above named "Simple") without any parameters. Any you code should work just with usual @Url.Action("TagChange");
MaxSunlight
Member
2 Points
1 Post
Re: In some cases UrlHelper.Action returns null under .NET 4.0 after working in .NET 3.5
Jan 03, 2011 08:57 PM|LINK
I use now .NET 4.0 MVC3 RC2
I found the same problem as you. Also, I was surprised that it's hard to find simple solution for that in the internet.
There is my solution:
You can note that if you call @Url.Action with route values, e.g. @Url.Action( "TagChange", new { id = 1 } ); then it will work ok. But of course, we don't want to pass fake void route values. So, let's just add another map route to Global.asax, for example:
routes.MapRoute("Simple", "{controller}/{action}", new { controller = "Home", action = "Index" }); routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });It's look like the issue that it requires route values even if they are declared as optional. So let's just add new map route (as shown above named "Simple") without any parameters. Any you code should work just with usual @Url.Action("TagChange");
action Route conflicts null url address