Antonija
Antonija

Reputation: 23

MVC 5 Razor reload current view

Is there any way to reload the current razor view by clicking on a link, without having to tell it the controller and action?

If I have a link on the Home/Index View, with the Home controller, I can do something like this:

@Html.ActionLink("some name", "Index", "Home")

But, if I want to have a link in the _Layout.cshtml that will be visible on all pages, I need something like this:

@Html.ActionLink("some name", default action of the current view, current controller, some parameter)

It probably can not be done with the actionlink, but is there some other way to do this?

Thanks in advance :)

Upvotes: 1

Views: 3112

Answers (1)

user3559349
user3559349

Reputation:

Your can provide null for the controller, action and route value arguments which will default to the current values.

For example if you have the following method in ProductsController

public ActionLink Details(int id)

and navigated to that url with ../Products/Details/2, then the following link in that page or its layout

@Html.ActionLink("Refresh Page", null, null, null)

will generate the same url, i.e. ../Products/Details/2

Note this works for route values (matching your route definitions), but will not add query string values

Upvotes: 1

Related Questions