strange mvc actionlink behavior
For some rea开发者_如何学Pythonson 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?
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
You have to add null
to the end of your Html.ActionLink
parameter, otherwise this length=8
will always try to make you crazy.
@Html.ActionLink("Browse", "Browse", "Property", new { id = item.ID }, null)
精彩评论