0

I'm struggling with navigation in asp.net mvc and URLs.

When you are visiting your profile at Facebook, the url is facebook.com/yourusername. At your profile there is a menu with the following links: Timeline, About, Friends etc.

When you click on one of these links, for example Photos, the URL is changed to facebook.com/yourusername/Photos, and the photos are rendered. The menu described above are still there, and so also the profile picture and the cover picture. Its like a partial view has rendered viewing the photos.

I want to accomplish this effect in my project, but I don't know how to do it. I have tried to do it with Partial view but the problem is that the URL is not changed when the partial view is rendered.

How should I structure it?

My Index.cshtml that belongs to Home-controller looks like this:

div class="centering col-lg-7 logged_in_mainboxes" style="padding: 0; position: relative">

    <div class="col-lg-12 coverPicture" style="background-image: url('/Content/Images/@Model.CoverPicture');">
       <div id="image-cropper">
            <div class="cropit-preview"></div>         
            <h3 class="coverPicTextStyle">
                @Model.Name
            </h3>
            <button type="submit" id="uploadCoverpicture" class="btn_style_2 btn" style="position: absolute; bottom: 10px; right: 10px;">Upload</button>
            <button type="submit" id="crop" class="btn_style_2 btn" style="position: absolute; bottom: 50px; right: 10px; display: none;">Done</button>
            <input type="file" class="cropit-image-input" id="coverUpl" style="display: none;" />
        </div>
        <div class='progress' id="progress_div">
            <div class='bar' id='bar1'></div>
            <div class='percent' id='percent1'></div>
        </div>
        <input type="hidden" id="progress_width" value="0">
    </div>
    <div class="col-lg-12 pull-left">
        <div class="user_menu">
            <ul>
                <li>@Html.ActionLink("Wall","Wall","Home")</li>
                <li>@Html.ActionLink("Music", "Music", "Home")</li>
                <li>@Html.ActionLink("Photos", "Photos", "Home")</li>
                <li>@Html.ActionLink("Videos", "Videos", "Home")></li>
                <li>@Html.ActionLink("About", "About", "Home")</li>
            </ul>
        </div>
    </div>
    <div class="col-lg-7 pull-left" style="margin-top: 15px;">

    </div>
    <div class="col-lg-3 pull-right" style="border-left: 1px solid #ddd; margin-top: 15px; ">
        asdasd
    </div>
</div>
halfer
  • 19,824
  • 17
  • 99
  • 186
Bryan
  • 3,421
  • 8
  • 37
  • 77
  • You could do that by defining routes - say `url: {username}/Photos` and `defaults { controller = "Photos", action = "Index" }` and redirect to that method, passing the user name (the menus etc would be just part of the layout) –  May 20 '16 at 03:50
  • @StephenMuecke: But I don't want that user specific menu to be a part of the Layout-file. – Bryan May 20 '16 at 03:53
  • If its a user specific menu, then you generate it in the layout by using `@{ Html.RenderAction(...); }`, passing the username (or ID) to the a method that generates the menu items based on the user –  May 20 '16 at 03:55
  • @StephenMuecke: Sorry, I dont understand your solution. I have the all the layout of the profile inside my Index.html that belongs to the Home-controller. Check my updated question. – Bryan May 20 '16 at 03:57
  • @StephenMuecke: Yes I have? – Bryan May 20 '16 at 04:20
  • Now I do not understand you previous question - there is no 'user specific menu' in the view you have shown. And where is the link that you want to navigate to the `{username}/Photos` page? (do you mean `
  • @Html.ActionLink("Photos", "Photos", "Home")
  • `? - that's not even passing the username to the `Photos()` method) –  May 20 '16 at 05:04
  • @StephenMuecke: I want this: When you click on any of the links(Wall, Music, Photos...), I want a Wall-partial, Music-Partial, Photos-partial to render In my col-lg-7-div below. When the specified partial has renderd, I want the URL to change to the url for the partial view. So, If I click on the Wall link, the Wall-partialview should render inside the div, and the url should change from localhost123 to localhost123/Home/Wall Ignore the {username} in the URL for now. That can be changed later. – Bryan May 20 '16 at 05:12
  • For that you going to need a [Single Page Application](http://www.asp.net/single-page-application). Otherwise, you will need to follow the normal pattern and redirect to another page when you click on one of those links (and all the code in the view you have shown would be in the layout) –  May 20 '16 at 05:18
  • And ignore the answer by Bharath theorare - it does nothing to solve your problem :) –  May 20 '16 at 05:20
  • @StephenMuecke: It must be another way to solve this. Facebook Is not a single page application. – Bryan May 20 '16 at 16:02
  • Then why not just redirect? –  May 20 '16 at 22:00
  • @StephenMuecke: And how should I do with the menu then? Coverpicture etc etc? – Bryan May 21 '16 at 02:26
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/112556/discussion-between-stephen-muecke-and-bryan). –  May 21 '16 at 02:26
  • @StephenMuecke: Im still struggling with this. You said that I should move the menu into the layout file. But IF I do that, the menu Is displayed everywhere on every page? I don't want that. I assume that I must have different layouts to use in my Views? I only want to show this menu when U are visiting a profile(a member of the site). The coverpicture, the menu, the profile picture should still be there when you click any of the links. Like on facebook. Where should I put this "Static" content that should always be visible when visiting a profile? – Bryan May 21 '16 at 05:20