I have the following route:
routes.MapRoute(
"Power", // Route name
"Power/{id}", // URL with parameters
new
{
controller = "flood",
action = "index",
id = UrlParameter.Optional
}
);
and the following address which I call:
<a href="/Power/" >
Now I would like to do the above call with an Html.ActionLink like this:
@Html.ActionLink("xxx",
"index",
"flood",
new { "Power" },
null
)
It seems not to work as I get an error "Invalid anonymous type declaration" where I have new { "Power" }. Can someone give me some advice and get me on the correct track.
I would also like to be able to call the following with another link:
<a href="/Power/001" >`
thanks
ps. Please note I am using MVC3. I understand the syntax for this changed from version 1 > 2 > MVC3.
Use a RouteLink instead of an ActionLink:
@Html.RouteLink("xxx", "Power", new { id = "123" })
or if you specify the controller and the action with ActionLink and based on your route definition order the proper route should be picked:
@Html.ActionLink("xxx", "index", "flood", new { id = "123" }, null)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With