Does anyone know how to pass Content/ContentPlaceholder information from a page, up through it's master page, to the parent master page?
Like this example, but with content defined in ChildFile (the page), being output in ParentMaster (q matster page one level higher in the nesting).
AFAIK this is not possible. I haven't found a perfect solution to this myself, but usually what works well for a little amount of possibilities (such as a 3-choice navigation bar) is a deriving secondary master pages from the master page and using those in your views. Another solution one is would be using javascript to manipulate the master page's content. A third one would be to isolate the content you want to change from the client page into a separate contentplaceholder and specify that on the client page.
Edit: With the arrival of Razor, this problem is now perfectly solved: Simply put your variables in the ViewBag in the child view and read it in the layout.
Use properties, pass them through and let the main master page decide what to do upon rendering
Related
Being relatively new to MVC I have been struggling for the past several weeks getting my layout to work.
I have managed to get myself really twisted into knots. So instead of trying to explain and unravel my mess perhaps instead someone could explain how I would accomplish the following at a high level.
_Layout this would have all the css js etc. It would also have basic structure.
Of course HTML tags not allowed in code block....each render is in a div.
#RenderPartial(Header)</div>
#RenderBody()</div>
#RenderPartial(Footer)</div>
RenderBody is Index.cshtml and it would be broken into three pieces
#
#Html.Partial(NavMenu, model)</div>
#Html.Partial(SubNavMenu, model)</div>
#Html.Partial(MainContent, model)</div>
I have this basic layout and it looks fine until you click one of the menu items.
The menu items render as:
<a class="k-link" href="/stuffroute">Stuff</a>
That route goes to a controller that returns a view and that navigates away from the above arrangement in Index.cshtml. So I end up with the header, footer, and subdash nav....
So the question is...
How do I route / orchestrate my layout to not lose the differing pieces?
Partials don't do anything for you here. You're essentially asking about how to create SPA (single page application), although in this case your application will have other pages, it's just that the index view will act like a SPA.
That requires JavaScript, specifically AJAX, to make requests to endpoints that will return HTML fragments you can use to replace portions of the DOM with. For example, clicking "Stuff 1" causes an AJAX request to be made to the URL that routes to FooController.GetSubNav([stuff identifier]). That action then would use what was passed to it to retrieve the correct sub-nav and return a partial view that renders that sub-nav. Your AJAX callback will then take this response, select a portion of the DOM (specifically the parent of the sub-nav) and insert the new HTML as its innerHTML.
If you're going to be doing a lot of this, you'll want to make use of some client-side MVC-style JavaScript library, like Angular for example. These make it trivial to wire everything up.
In my new Rails project,I want to provide my user two kinds of category view mode
:one is List mode,other is Detail mode.
In List mode,the category page will just show the title of the article.In Detail mode,the page will show the title and the content.I want to use a 'switch' to control this two mode,when user choice 'List mode',all the category page will be shown in List mode.When they choice 'Detail mode',all the category page will be shown in Detail mode.
I think I could use different Action control this two view mode,so my question is how to set a 'switch' to control these different Actions in the whole site? A Variable?
Also welcome another solution.
Thank you.
You could use a variable and railscasts shows the way again. The new design of railscasts.com implements this sort of a design, where-in it provides an option to view articles in a list/grid fashion.
Since, railscasts is an open-source project, I encourage you to browse through the code in
episodes_controller
and the view episodes#index (he uses params[:view] to switch between different listing styles)
And you'll know exactly what to do.
I currently have 2 page types in my Orchard CMS setup. One is for the front page, one for a detail page. On the front page, I have removed the body from being displayed, so that it just shows 2 HTML widgets.
Is there a way so that when someone edits this page, they don't get a body section?
A placement file might also do the trick: placement also works for the admin ui... That could enable you to make it show or not without requiring two different content types.
You can remove the Body Part from the page content type you use for the front page. This way people who edit this page won't see the editor for body content and the body won't be rendered at all.
HTH
I have a website that will contain 2 type of layout.
With no columns
With 2 columns
Header, footer and lots of other parts are the same for both, but inside the main content, there 2 separate layouts and I'd like to choose between 2 site masters. How would I go about accomplishing this?
I was thinking about making a main site master and have the one with the 2 column inherit from that. If that is the correct method, what are the keywords to google for, or you are free to explain inheriting site masters here.
Thank you,
Master pages can inside a master page themselves just like any other view. Just specify the master's MasterPageFile directive as usual:
<%# Master Language="C#" MasterPageFile="~/Views/Shared/App.Master"
Inherits="System.Web.Mvc.ViewMasterPage" %>
Your views can choose to use the overall master page or the nested one as their masters.
Alternately, you can set the MasterPage of your views dynamically in several ways. The regular View() method has an overload to specify the master page:
return View("SomePage", "MasterPageFileHere");
or even better would be to specify an action method to do it for you globally. You can see a good walkthrough of that here.
the routes are as follows
site.com/{section1}/{page1}
site.com/{section1}/{page2}
site.com/{section2}/{page3}
etc.
the pages are 2 column each where the left bar is different for each section
the page content is fetched from the database based on section + page combination
I'd like to make the page markup/layout/css be done/uploaded by the user
Questions:
hopefully this is implemented somewhere? any links?
how much can this be dumbed down?
what/how can checks be enforced so that the few required tags/markup are present/visible?
any gotchas?
figured it out using ActionAttribute