I have a controller which accepts URLs in the following two formats:
- Network/AddOrEdit -> renders a blank form on a page to add a new network object
- Network/AddOrEdit/[id] -> renders a page with prepopulated form to edit the network object with ID [id]
Obviously it's the same view being used in each instance - one of my design goals is to use the same view for adding and editing purposes.
The master page contains a link to the add page like this:
@Html.ActionLink("Add", "AddOrEdit", "Network")
Ordinarily this renders correctly as /Network/AddOrEdit
.
However, when I am on the edit page (i.e. the current URL is in the format Network/AddOrEdit/[id]
), then the Add link renders with that ID on the end - so the add link actually points to the edit page. This is not what I want!
So for some reason MVC seems to be allowing the current ID from the query string to interfere with the rendering of the ActionLink.
Any suggestions what I can do about this? :(