Reputation: 3844
i am receiving GET requests like this
http://localhost/controller/List#SearchGuid=755d259d-e7c9-4c5a-bf2a-69f65f63df8d
and i need to read the SearchGuid which is after the #. unfortunately the HttpRequestBase seems the hide everything past a #.
does somebody know how i could still read the SearchGuid from within the controller action?
tia.
Upvotes: 9
Views: 7060
Reputation: 489
'#' Fragment is accessible client-side only, however IE8 submitting URL include #fragment part.
You can use Ajax to make it works. Something like:
var fragment = location.hash; // on page load
$.get('/yoururl' + '?' + fragment.replace(/^.*#/, ''));
It will looks like you are requesting URL#fragment on client-side, but actually, it will request URL?fragment and you can work with it on server-side.
One thing you should remember about - server page will be requested twice, so second one (Ajax request - check the request header "X-Requested-With=XMLHttpRequest") you should take.
P.S. Google applications using same solution, as I'm seeing from Firebug.
Upvotes: 2
Reputation: 48066
If you want to process url "fragments" (that's what those things after the '#' are called), you'll need to do so client side. Fragments are not transmitted to the server.
Either redesign the protocol to use a query string (replace '#' by '?'), or use javascript on the client to do the necessary processing - which may include making a server request that encodes the fragment in a URI query string.
Upvotes: 3
Reputation: 176
You can get that part in JavaScript on the client side using window.location.hash, set it to some hidden input onsubmit so they'll also get sent to the server.
Upvotes: 2