Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8298081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:38:42+00:00 2026-06-08T15:38:42+00:00

I’m building an Asp.net mvc 3 application. What I want to do, is a

  • 0

I’m building an Asp.net mvc 3 application. What I want to do, is a profile page (pretty mutch like the stackoverflow profile page), and the content of this page will be splited in tabs, each tab is represented by an PartialView.

When the user click on the tab X, I want to refresh only the tab area, without refreshing all my page. And in the same time changing my URL adress, so if the user click on the browser refresh button, it refresh the page with the selected tab. Is this possible ?

What I already know, is how to get data using AJAX, and replace the content of my view. I’ve read this post , I found it interesting, but it refresh all the page.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:38:44+00:00Added an answer on June 8, 2026 at 3:38 pm

    You are on the right track. You will need to use both ajax to get the html to render without refreshing the page, as well as use push state to update the URL to include the current tab.

    You could do these things as separate operations, but I would suggest using PJAX. With PJAX you will need a little additional logic in your server to decide whether to return the full html page with the layout, or just return the partial (a PJAX request).

    Here is our Foo controller. Index has a default selected tab of “Bar”. The Bar and Baz actions return the Index view, but with different tabs being the selected tab. If it is a PJAX request, then all we need is the partial view that fills in the tab content.

    public class FooController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.SelectedTab = "Bar";
            return View();
        }
    
        public ActionResult Bar()
        {
            if(Request.Headers["X-PJAX"] != null)
                return PartialView();
            ViewBag.SelectedTab = "Bar";
            return View("Index");
        }
    
        public ActionResult Baz()
        {
            if (Request.Headers["X-PJAX"] != null)
                return PartialView();
            ViewBag.SelectedTab = "Baz";
            return View("Index");
        }
    }
    

    Inside of the Foo/Index.cshtml we have the Razor code that will determine what partial view to render based on ViewBag.SelectedTab.

    @{
        ViewBag.Title = "Foo";
    }
    
    <h2>Foo</h2>
    
    <ul>
        <li><a class="tabs" href="@Url.Action("Bar", "Foo")">Bar</a></li>
        <li><a class="tabs" href="@Url.Action("Baz", "Foo")">Baz</a></li>
    </ul>
    <div id="tab_content">
        @if(ViewBag.SelectedTab == "Bar")
        {
            @Html.Partial("Bar")
        }
        @if (ViewBag.SelectedTab == "Baz")
        {
            @Html.Partial("Baz")
        }
    </div>
    
    @section scripts
    {
        <script type="text/javascript">
            $(function() {
                $(".tabs").pjax("#tab_content");
            })
        </script>
    }
    

    The script section at the end is how you wire up PJAX. You are telling it, for all hyperlinks with the tabs class use pjax to dynamically load and render the html resulting from the href into the container with the id tab_content and update the url in the browser to be the url from the href.

    Each tab’s partial view is fairly simple in this scenario

    Bar.cshtml

    <p>This is the Bar tab. No pun intended.</p>
    

    Baz.cshtml

    <p>This is the baz tab.</p>
    

    This is obviously a very simplified solution. You typically would want to use a presentation model to handle the logic of the view. Also, I have intentionally left out any tab styling to demonstrate that this technique can be used on any type of link. It is not limited to only tabs.

    The full source code for this example can be on my GitHub site.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.