Back button for previous partial view

In my .Net MVC4 project, the view contains partial views, the partial views are replaced with another after each matching Ajax.Beginform

with the InsertionMode = InsertionMode.Replace,

So senario option

  • Partialview1 displays the first call Ajax.Beginform

  • Submit form, partialview2 render to 2nd Ajax.Beginform

    , so partialview1 is replaced by partialview2

3. The previous button resembles partialview1

I am wondering how to implement step 3 that goes into the previous partial view with something as simple as history backwards.

+3


source to share


1 answer


First way: I think the best way to do it with the browser's back button is to usehistory.pushState

How to implement this depends on your situation on View

.

Some links about pushState

:

http://rosspenman.com/pushstate-jquery/

https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history



Second way: If you don't want to use Back buttom browsers you can use js:

function getBack()
{
   $.ajax({
     type: "GET",
     url: '@Url.Action("ReturnPartialViewControllerMethod")',
     success: function(data) {
           // data is your view
          $('#divForParticialView').html(data);
     }
   });
}

      

and in your Html:

<a href="javascript:void(0);" onclick="getBack()">Get Back</a>

      

0


source







All Articles