How to access AJAX hash values ​​in ASP.NET MVC?

I am considering using a hash method to create static URLs for content that is controlled by ajax calls in Asp.Net MVC. The proof of the concept I'm working on is the profile page /user/profile, where you can view and edit different sections. You can always request the following URL /user/profile#passwordto access directly your profile page in the password change section

However, I am wondering if I’m starting it badly, because apparently I can’t get access to this part after the hash, except for declaring the route value for the hash in global.asax. So I wonder if this is the right way to access this part of the url?

Should I declare a route value or is there another way to work with hash values ​​(wireframe, javascript or mvc)?

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

+3
source share
3 answers

The fact is that the part that follows the hash (#) is never sent to the server in an HTTP request, so the server does not read it at all. Therefore, you do not need to spend time searching for something that does not exist.

, , -, .

+7

- document.location.hash .

+3

This can be done in code if necessary ...

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

should work fine

0
source

Source: https://habr.com/ru/post/1766978/


All Articles