Link to home
Start Free TrialLog in
Avatar of Sailing_12
Sailing_12

asked on

MVC app cancel button navigation

I have an MVC form which a user can arrive at from two entirely different controllers/views - I have a cancel button on the form that I would like to simply navigate the user back to their previous page, whichever one they came from.

The button is a straight HTML anchor, not an actionlink:
<a class="btn btn-primary cancelNav" href="">Cancel</a>

Open in new window


On the client-side, I am using unobtrusive jQuery to attach an anonymous function to the link:
    $(document).on('click', '.cancelNav', function () {
        window.location.assign(document.referrer);
    });

Open in new window


I have experimented with numerous approaches here, using window.location, window.history and have verified that the correct URL with params is being passed, but all result in:
"System.ArgumentException: The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Edit(Int32)'"
yet I can click the browser's back button with no issue.

Can someone tell me why?
Avatar of leakim971
leakim971
Flag of Guadeloupe image

the code you posted is not your issue
>>"System.ArgumentException: The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Edit(Int32)'"

is the previous page an edit page which required a parameter named as "id"? you need to provide that Id as a numerical value.
ASKER CERTIFIED SOLUTION
Avatar of Sailing_12
Sailing_12

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sailing_12
Sailing_12

ASKER

Was able to resolve on my own.