I am faking an autopostback using jquery since I am using asp.net mvc. It's being performed in a select list (dropdownlist) like this:
$(document).ready(function() {
// autopostback for character drop down list
$('#playerCharacters').change(function() {
var charId = $('#playerCharacters option:selected').val();
window.location = "/Character/SetDefault/" + charId;
});
});
Now in /Character/SetDefault/[charID] (controller, action, ID) I am trying to access the referring URL using this:
Request.UrlReferrer
But it's coming up null. Any ideas on why that is?
I think setting the window.location directly is treated by the browser the same as it would treat the user directly entering a new URL into the location bar. This means that there's no referrer since referrers are about one page directly referring to another, (eg. via a link) not the browser just going to another page...
Easiest way I can see to solve your issue is to make sure your drop down list is in a form that posts (or gets) to /Character/SetDefault & then make your javascript submit the form like this:
$('#playerCharacters').change(function() {
this.form.submit();
});
You'll then just need to change your SetDefault action in your controller to have a playerCharacters parameter so that the MVC will bind the form's request value to your method properly.