Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a "Back" button, only if there is a back (MVC)

Right now I'm using <a class="bottomNav" onclick="history.go(-1); return false;" href="#">Back</a><br />
But then it will always be displayed, even when the "back" button won't lead anywhere.
How can I check if there is a "back" before displaying the button?

I wanted to check the action and controller, for example: if(ViewContext.Controller.ValueProvider.GetValue("controller").RawValue != "Home")
But it is not accurate because I still need the "back" sometimes

like image 849
user990635 Avatar asked Apr 20 '12 05:04

user990635


People also ask

What is ActionResult () in MVC?

An action result is what a controller action returns in response to a browser request. The ASP.NET MVC framework supports several types of action results including: ViewResult - Represents HTML and markup. EmptyResult - Represents no result.

How do I return specific view on a controller?

To return a view from the controller action method, we can use View() method by passing respective parameters. return View(“ViewName”) – returns the view name specified in the current view folder (view extension name “. cshtml” is not required. return View("~/Views/Account/Register.

What is razor view in MVC?

Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML.


1 Answers

@if(Request.UrlReferrer != null)
{
    <a class="bottomNav" onclick="history.go(-1); return false;" href="#">Back</a><br />
}
like image 108
Chuck Norris Avatar answered Nov 10 '22 01:11

Chuck Norris