Ad

What Is A Good Way Of Creating A Back Button To Different 'coming From' Pages

- 1 answer

I have two different pages, from which a user can click on a 'details' link and go to the details page.

On the details page, I have a 'back' button, which leads the user to the originating page, being one of the two original pages of course.

There is also one extra issue: in one of the return links, I must specify an extra anonymous object.

my view code right now is:

@{
    MvcHtmlString backLink = null;
    if (Model.ReturnPage == MatchResultReturnPage.Search)
    {
        backLink = Html.ActionLink("GoBack", "Search", new {search = true});
    }
    else
    {
        backLink = Html.ActionLink("GoBack", "Dashboard");
    }
} 

In the controller I now look in the url.referrer if it contains 'dashboard', then I set the Model.ReturnPage to 'Dashboard'.

Is there a cleaner way of doing this?

Ad

Answer

Put the ReturnLink as a property on your model and set it inside the controller, which will alleviate the need for you to put that logic in the view.

Ad
source: stackoverflow.com
Ad