views:

40

answers:

1

I'm considering using the hash method to create static urls to content that is managed by ajax calls in a Asp.Net MVC. The proof of concept i'm working on is a profile page /user/profile where one can browse and edit different sections. You could always ask for the following url /user/profile#password to access directly to you profile page, in the change password section

However, i'm wondering if i'm not starting this the bad way, since apparently i can't access the part after the hash in any way, except by declaring a route value for the hash in global.asax. So i'm wondering if this is the right way to access this part of the url?

Am i supposed to declare a route value, or is there another way to work with hash values (a framework, javascript or mvc)?

Edited to add: In pure javascript, i have no problem using the window.location.hash property, i'm not sure though how standard it is in today's browsers, hence the question about a javascript framework/plugin that would use it.

+1  A: 

The thing is that the part that follows the hash (#) is never sent to the server into the HTTP request so the server has absolutely no way of reading it. So no need to waste time in searching for something that doesn't exist.

You could on the other hand tune your routes to generate links that contain the hash part so that client scripts can read it.

Darin Dimitrov
i'm not sure i follow you; even if i change my urls to generate the hash part in urls, if the browser can't see the hash what's the point? Isn't it better to hand everything to the javascript and let him in charge of setting/reading the hash at page load?
samy
The browser and javascript can see it using `window.location`. It's the server that can't.
Darin Dimitrov
so what you're saying is that i should have two ways of naming an url? either directly for the server? or with a hash, and in this situation the server would render the base page and the javascript would query the part corresponding to the hash... (that is in case my site works w/out javascript, if not the point is moot :) )
samy
ok, it took me some time to understand what your answer was. thank you!
samy