2

In my application I have a layout page for viewing the project:

This page have 4 sub-pages (Details, Photos, addresses and comments).

Example:

/myproject = Open the details page

/myproject/Photos = Open the Photos page

/myproject/Addresses = Opens the page addresses

/myproject/Comments = Open the page of comments

Question

How to use # to load pages via ajax to the URL?

Example

/myproject = Open the details page

/myproject#Photos = Open the Photos page

/myproject#Addresses = Opens the page addresses

/myproject#Comments = Open the page of comments

In page layout where I have four buttons, click on the photo for example, the page would be loaded via ajax. and url go

from /myproject

to /myproject#Photos

Resume

How to use '#' in asp.net MVC?

ridermansb
  • 10,779
  • 24
  • 115
  • 226
  • Looking at your comments in the answers, are you attempting to create links that have the hash tag in it e.g. `myproject#Photos` and you want them to simply scroll to the that section in the currently loaded page? – dnatoli Nov 21 '11 at 22:39
  • I've updated my answer, let me know if that is not clear enough. – dnatoli Nov 22 '11 at 04:37
  • See also this question. http://stackoverflow.com/questions/274586/including-an-anchor-tag-in-an-asp-net-mvc-html-actionlink – Nathan Koop Sep 13 '12 at 14:06

2 Answers2

1

They are generally called URL fragments and are used as bookmarks on a page to navigate to different sections of that page. When clicked they will scroll down the currently loaded page to the matching tag name. I would recommend against using them as paths to different pages.

You can use them as bookmarks by specifying the fragment in the Htmlhelper:

@Html.ActionLink("My Photos", "Action", "Controller", null, null, "Photos", null, null)

Then in your Photos partial that represents the Photos sub-page, set the html id attribute to "Photos" in the div or label or whatever represents the beginning of the Photos partial. The link created with the @Html.ActionLink will look for a html element ID that matches the word you typed into the fragment.

See LinkExtensions.ActionLink Method for more details.

dnatoli
  • 6,972
  • 9
  • 57
  • 96
  • I do not need to do anything else, just the fact that the ID match the fragment (or hash) the scroll will be done? – ridermansb Nov 22 '11 at 10:42
0

Sorry, brain fart there... You need everything client side...

I'd use the following jQuery plug-in to parse the URL fragment:

http://benalman.com/projects/jquery-urlinternal-plugin/

and then call MyDiv.Load('yourcontenthere') to load the content you'd like into the desired DIV.

Hotrodmonkey
  • 2,924
  • 3
  • 20
  • 25
  • 1
    Wrong on both counts. He's referring to pre-HTML5 AJAX history, and you can't do it with routing. – SLaks Nov 21 '11 at 00:33
  • Exactly @SLaks! There are four pages that are loaded via ajax. What I need is a way to load the contents via ajax inside the div, and indicate in the url with # (hash, did not know the name of this feature) what content is being displayed. – ridermansb Nov 21 '11 at 02:39