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:
On the client-side, I am using unobtrusive jQuery to attach an anonymous function to the link:
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.ActionResu lt Edit(Int32)'"
yet I can click the browser's back button with no issue.
Can someone tell me why?
The button is a straight HTML anchor, not an actionlink:
<a class="btn btn-primary cancelNav" href="">Cancel</a>
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);
});
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:
yet I can click the browser's back button with no issue.
Can someone tell me why?
the code you posted is not your issue
>>"System.ArgumentExceptio n: The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResu lt 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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Was able to resolve on my own.