Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strange mvc actionlink behavior

For some reason my action link behavior sends users to a strange place.

I have two classes: locations and properties.

From the locations view I want a link that leads the users to browse properties in that location:

@Html.ActionLink( "Browse", "Browse", "Property", new { id=item.ID } )

So I would like the HTML link and the method to have the same name: "browse".

Instead of having it in the current controller/view I want to send the ID to the properties controller. Notice the word "Location" does not appear in the line above.

But the URL ends up:

http://localhost:50164/Location/Browse?Length=8

I want it to end up like this:

http://localhost:50164/Property/Browse?Length=8

The API in MVC 3 appears to be:

ActionLink( "text to display as HTML link", "action name", "controller", "parameters" )

Which seems to be how I did it, but I get unexpected results.

What am I doing wrong?

like image 536
micahhoover Avatar asked Mar 22 '26 10:03

micahhoover


1 Answers

There is no method signiture ActionLink(HtmlHelper, String, String, String, Object).

It is using the ActionLink(HtmlHelper, String, String, Object, Object) which has the following parameter names:

htmlHelper, linkText, actionName, routeValues, htmlAttributes

Use this method instead:

@Html.ActionLink( "Browse", "Browse", "Property", new { id=item.ID }, null)

which has the following parameter names:

htmlHelper, linkText, actionName, controllerName, routeValues, htmlAttributes

See the full list of overloads

like image 157
The Scrum Meister Avatar answered Mar 25 '26 11:03

The Scrum Meister



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!