Xm7X
Xm7X

Reputation: 861

Use JavaScript or MVC razor to go back a page

With the HTML tag <a> onclick should I use

onclick="history.go(-1);"

or

href="@Url.Action("index", "somecontroller")"

What is the actual difference between these two methods as seen by a browser?

Upvotes: 0

Views: 1744

Answers (1)

Tushar Gupta
Tushar Gupta

Reputation: 15923

You can either use: Action Links : which creates <a href=".."></a> tag automatically as

For example:

@Html.ActionLink("link text", "someaction", "somecontroller", new { id = "123" }, null)

generates:

<a href="/somecontroller/someaction/123">link text</a>

or

Url.Action as For example:

Url.Action("someaction", "somecontroller", new { id = "123" })

Upvotes: 2

Related Questions