3

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.

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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?
The browser and javascript can see it using window.location. It's the server that can't.
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 :) )
ok, it took me some time to understand what your answer was. thank you!
3

Send the hash value document.location.hash as a parameter to the controller action of your choice.

Comments

0

This can be done in the code if needed...

RedirectResult(Url.Action("profile") + "#password");

should work fine

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.