Question

I have an MVC5 app with a nav bar on top that has a link to the Entries Index page. This lists all entries in the system. The nav bar code is in a shared view _Layout.cshtml.

@Html.ActionLink("Entries", "Index", "Entry")

This normally builds the proper link of "/Entries/Index".

However those entries can be filtered by CompanyID with the {id} param. So /Entries/Index/1 would give me Entries for that Company. When you are on this screen the nav link is no longer simply /Entries/Index, but /Entries/Index/1. The View seems to know that it is on that controller and adds the param.

I have tried the following to no avail.

@Html.ActionLink("Entries", "Index", "Entry", new {id=null }, null)

This even the syntax checker says is invalid. Unable to assign a null to an anonymous property for the id=null.

Not sure where to go next. I just want to force that link to be without a parameter no mater from where it is called. I don't want to have to hard code it.

Était-ce utile?

La solution

Try:

@Html.ActionLink("Entries", "Index", "Entry", new {id="" }, null)

This will clear out the 'ambient ' route values from your nav links. Here's a blog post which explains it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top