Perhaps I'm just having a bad day.
MVC views seem to be displaying _Layout.cshtml even when I do not specify layout. Is it defaulted somewhere?
The page in question is my KeywordAdmin.cshtml partial view which looks like this (this is the file in its entirety):
<div class="form-horizontal">
<div class="row">
<div class="col-md-3">
Test column 1
</div>
<div class="col-md-4">
Test column 2
</div>
<div class="col-md-5">
Test column 3
</div>
</div>
</div>
When I navigate to localhost/Keyword/KeywordAdmin I see this with the header and footer defined in _Layout.cshtml. If I wanted it to use that layout, I would have specified it.
The layout system is in place for helping you keep things uniform. Based on your statement, it seems you'd prefer not leverage it, which you can do too.
Look in _ViewStart.cshtml within the Views folder.
If KeywordAdmin.cshtml is within a subfolder, you may have another _ViewStart.cshtml in that folder which would take precedence.
If you set Layout = ""; you'll go without the layout. If KeywordAdmin.cshtml is just an oddball item and it shouldn't use your normal layout, it would be recommended to add to the top of KeywordAdmin.cshtml:
#{
Layout = "";
}
If you're wanting to leverage MVC in a way that meets your previous expectations, I'd recommend setting at the top of _ViewStart.cshtml:
#{
Layout = ""; // most likely "~/Views/Shared/_Layout.cshtml" right now
}
and then on any pages where you do wish to leverage the layout, adding:
#{
Layout = "~Views/Path.../LayoutName.cshtml";
}
Related
I have been migrating codes from .NET(webform) to .NET Core :
Within _Layout.cshtml, the following tags <hr>, <section> covers the full width(e.g. 100%) of the html as expected.
However, inserting similar tags within the content pages such as Index.cshtml do not cover the full width of webpage, for some reasons.
Even after adding in Index.cshtml
#page
#model IndexModel
#{
ViewData["Title"] = "Home page";
}
//test
<div class="container-fluid">
<hr style="width:20000%" />
</div>
one ends up with the horizontal line leading the expecting result from the right end side only, as opposed to the left-hand side, thus leaving me puzzled.
I was expecting to face issues following the code(s) migration on items other than the beforementioned tags. Thus any suggestion would very be appreciated.
For this phenomenon, I think you should take a look at the official documentation on _layout.
Doc:What is a Layout.
Article:What are Layout, _ViewStart, RenderBody, and RenderSection in MVC?.
RenderBody() is called to render the content of a child view. Any content on said view that is not in a #section declaration will be rendered by RenderBody(). Using the Layout view above, that means that all content in a child view will be rendered inside the . This allows us to separate layout that is common to all views from layout that is specific to a single view.
If we need some part of the page to change based on which child view the user is on,you can use RenderSection().
In your _layout:
#RenderSection("Body", required: false)
In your view:
#section Body
{
<div class="container-fluid">
<hr style="width:20000%" />
</div>
}
This is the first time we have tried Umbraco and we are following a official tutorial to create a Arcticle/News functionality as an example.
We basically started from the top here
So, first we created a Homepage and so a Masterpage, and everything in between until we reach this point.
And everything displayed works, we have a overview, the Macro/Partial View is working great.
But when we want to navigate to the actual ArticleItem, we run into the error mentioned in the title.
Cannot bind source content type Umbraco.Web.PublishedContentModels.ArticlesItem to model content type Umbraco.Web.PublishedContentModels.ArticlesMain. Both view and content models are PureLive, with same version. The application is in an unstable state and should be restarted.
Now, my guess is that it is an issue with the Masterpage being the ArticlesMain template, and this enforces that Model to be used/passed down to the ArticlesItem pages. But my MVC is quite rusty, so it seems I can't figure out a solution myself at this time.
The code used is copied 1:1 from the tutorial to make sure we didn't mess anything up, but no dice so far. We also did everything in the Umbraco CMS, our IDE (VS) was not used.
/Views/ArticlesMain.cshtml
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
<ContentModels.ArticlesMain>
#using ContentModels = Umbraco.Web.PublishedContentModels; #{ Layout = "HomePage.cshtml"; }
<div id="main-container">
<div id="main" class="wrapper clearfix">
<section>
<h2>#Umbraco.Field("articlesTitle")</h2>
<p>#Umbraco.Field("articlesBodyText")</p>
<p>#Umbraco.RenderMacro("listArticles")</p>
</section>
</div>
<!-- #main -->
</div>
<!-- #main-container -->
/Views/ArticlesItem.cshtml
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
<ContentModels.ArticlesItem>
#using ContentModels = Umbraco.Web.PublishedContentModels; #{ Layout = "ArticlesMain.cshtml"; }
<h1>#Umbraco.Field("articlesTitle")</h1>
<article>
<h2>#Umbraco.Field("createDate")</h2>
<p>#Umbraco.Field("articleContents")</p>
</article>
/Views/MacroPartials/listArticles.cshtml
#inherits Umbraco.Web.Macros.PartialViewMacroPage
#{
var selection = CurrentPage.Children.Where("Visible").OrderBy("CreateDate desc");
#* OrderBy() takes the property to sort by and optionally order desc/asc *#
}
#foreach (var item in selection)
{
<div class="article">
<div class="articletitle">#item.Name</div>
<div class="articlepreview">#Umbraco.Truncate(#item.ArticleContents,100) Read More..</div>
</div>
<hr/>
}
As for the Document Types, they looks exactly as in the tutorial's screenshots, I could provide those as well of course, including the set permissions.
I got some help from the official Umbraco forums, it turned out I did make a simple mistake.
If anyone ever stumbles upon this question, I'll just leave this here:
this is caused as the model that is used in the view is not of the correct type. You used Layout = "ArticleMain.cshtml" in your view for the ArticleDetails which causes the ArticleMain.cshtml to be used as a parent view. This view needs a model of type ArticleMain. Switching to "Layout=Master.cshtml" should solve the issue. At least this seems to be the master view in the tutorial.
Umbraco forum comment
I'm trying to build a basic documentation site using asciidoctor. One thing I am struggling with is how I can inject a standard site header (a banner with a logo and top-level navigation) into each documentation page.
I render my asciidoc directly to html from the command line. I have tried to find a way to somehow inject an extra div element and position it fixed at the top, but I can't figure out what mechanism to use for this. My early attempts involved using docinfo.html but that gets injected into the html in the <head> element, instead of the <body>.
I am aware that full-on publication systems like Jekyll allow me to configure "front matter" that can probably take care of this, but I was hoping there was a mechanism or trick using vanilla asciidoctor that can achieve this.
Ted Bergeron on the Mailing List mentioned a simple project:
Demo website created just using Asciidoctor.
Check the corresponding repo to see the files and how to create the site (just using one command).
In summary: simply create a header asciidoc file that includes your site nav (in the demo site this is done using table markup), without including a level-0 (document) title. Include this header file right at the top in every page of your site. Then render by just running asciidoctor *.txt on your project.
--embedded option + simple post processing
With this option, asciidoctor generates only the interior part of the <body> element.
For example:
main.adoc
= Super title
== Second level
asdf
== Also second level
qwer
then:
asciidoctor --embedded main.adoc
produces:
main.html
<div class="sect1">
<h2 id="_second_level">Second level</h2>
<div class="sectionbody">
<div class="paragraph">
<p>asdf</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_also_second_level">Also second level</h2>
<div class="sectionbody">
<div class="paragraph">
<p>qwer</p>
</div>
</div>
</div>
You can then just cat a header and closing footer, and you are done.
Tested with Asciidoctor 2.0.10.
I just go through the bootstrap framework, its a grid based css framework but I dont know how implement in IBM Websphere Portal 8.
code
<!DOCTYPE html>
<body class="lotusui30dojo tundra locale_en">
<div class="wpthemeFrame">
<header role="banner">
<div class="wpthemeHeader">
<a rel="dynamic-content" href="dyn-cs:id:customTheme_preview"></a>
<div class="wpthemeInner">
<div class="wpthemeLogo wpthemeLeft">
I suggest you to create a normal static HTML Prototype using Bootstrap. Once you make sue it's working properly (in responsive manner) you can start porting the source code to Portal. There are 3 parts:
First you have to copy paste the html part other than the middle content area (ie. the header part and the footer part) into theme_en.html in your custom folder. Then replace the css and JS links header part with
Then replace blocks of code with appropriate Dynamic Spot contents (JSP files). For instance something like,
<a rel="dynamic-content" href="res:/customTheme/themes/html/dynamicSpots/banner.jsp"></a>
Also, please make sure at the end of page you have this,
<div class="wpthemeComplementaryContent" id="wpthemeComplementaryContent" role="region" aria-labelledby="wpthemeComplementaryContentText">
<span class="wpthemeAltText" id="wpthemeComplementaryContentText" >Complementary Content</span>
<a rel="dynamic-content" href="co:config"></a>
</div>
Now we have to take the layout structure from the middle part of HTML area and use it for creating a Template Layout. Remember, in each template layout we have to keep the div for hidden widgets. Better way is to copy one existing layout.html file from Template Layouts and rename it and modify in that. If you are using Bootstrap, you don't have to use default WP classes. But few must be integrated, like DndRow,DndColumn, Componet-Container etc.
Now for each page specific styling, you can manage in Presentation template.
quick question here:
I am using DCE on Typo 6.1.5. I am trying to set an element out of the "container" div. But it rarely works.
<div id="contentMarginFix">..</div>
<div id="contact">
<div class="container">
<div class="gmaps">
</div>
</div>
</div>
I want to get the "gmaps" div in the "contact" div. Not in the "container" one.
Here is the DCE Template
http://gyazo.com/2c0a13746cdd834ebdb86a0b64fd10b1.png
And here is the template for the page
http://i.imgur.com/y2rwP6P.jpg
I was trying for two hours now maybe i just don't see it but i appreciate your help very much!
From the screenshots you provided I'd say it's possible the layout template is in the wrong place. Make sure the contact.html you use as a layout is in the right place.
If this is a basic fluid template directly in typo3 make sure the file is in the place you defined in your setup typoscript. Default would be something like this:
layoutRootPath = fileadmin/templates/Layouts/
If this is inside an extension the correct place for the layout template is
Resources\Private\Layouts
Be aware that in more recent extbase versions the naming conventions are more strict and require a capital first letter for the html files (so Contact.html)