I have the following structure:
Views:
Home
Articles
Partial Views:
Book
Classes
Intro
Faq
On the top of the page, in my header, is a navigation menu – containing multiple Ajax.ActionLinks that call into different methods in my HomeController class to fetch a particular partial view and then place that content in my center DIV. So I can click on the Faq link, and the content in the center DIV of my page will now contain the partial view for my Faq. Now, I have an Articles view that will look completely different and therefore needs to be separated as it’s own view as opposed to a partial view, and, the problem that I am running into is if I click on my Html.ActionLink for “Articles”, I am navigated to my Articles view, which is what I want, but then if I click on one of the other links that are Ajax.ActionLinks, I need (somehow) the view to change back to my Home view so that I can then retrieve the requested partial view and place that into my center DIV. Any idea how I can do this? Right now the AJAX.ActionLink, when being called while on my Articles View, is calling into my HomeController, but then trying to replace the content in my center DIV (which doesn’t exist in my Articles view), and additionally, it’s not loading the HomeView.
Any thoughts on how to best achieve this? Also, I am not using the Razor engine.
So, the navigational menu, which is a set of links, resides in my Site.Master file. Here is one of the links that I have:
<%= Ajax.ActionLink("Book", "LoadBook", new AjaxOptions() { HttpMethod = "Post", UpdateTargetId = "content", InsertionMode = InsertionMode.Replace })%>
When clicking on this link, the method LoadBook in my HomeController is called. Refer to the code below:
public ActionResult LoadBook()
{
return PartialView("Book");
}
In my Home.aspx view, I have the following code:
<div id="content">
<% Html.RenderPartial("Intro"); %>
</div>
This code will automatically load the partial view for my “intro” (introduction) by default whenever initially loading the Home view. So basically, since the link for “Articles” is Html.ActionLink (as opposed to Ajax.ActionLink), when it is clicked I am taken to the Articles view. When I click on, for example, the “Book” Ajax.ActionLink in my Site.Master header while on the Articles view, the code will try to update a “content” DIV with the “Book” partial view. This behavior is only wanted when on the Home view, for obvious reasons. So, how can I have different behavior for my Ajax.ActionLinks when viewing a view that is different than my Home view?
Thanks!
Chris
This sort of architecture is going to give you lots of problems. For stanrtes, you can’t link to any pages. All your content happens in your main page.
This works ok for an app like GMail, but most people will be confused as to why they can’t save a shortcut to a page, or send a link to a friend.
HTML is designed to have a unique URL for each page. You’re fighting upstream trying to do something different. Suppose you want to use fragments to jump to other sections of your page. you can’t do that.