Customize Layout templates In MVC3 - asp.net-mvc-3

I known There is a default _Layout.cshtml file in Asp.net MVC just like MasterPage in Asp.net Web Site. Can I define multiple layout templates in my MVC app? If so ,How to make it? Please give me some code example . Thanks.

You can create multiple Layout pages and use it in differnt views. You may mention the new layout pages inside your views by mentioning the Layout property in your views.
Create a new View and name it as _AdminLayout.cshtml under Views/Shared folder. You may create your HTML markup for your master page template there. Make sure you have #RenderBody() section in your Layout page so that the content of your normal views will be replaced here when it renders.
<html>
<head>
</head>
<body>
<h1>My new Layout</h1>
#RenderBody()
</body>
</html>
And if you want to use this Layout in a view, you can do it like this
#{
Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<p>The content here will be present inside the render body section of layout</p>
If you want to use the new Layout for all the Views by default without explicitly mentioning like the above code, you can do it in the Views/_ViewStart.cshtml file
#{
Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

Related

How Load asset only once laravel 5.3?

How Load asset only once. if i open dashboard, all asset will be load and then i open other page, not load asset second time..
how to make load asset only once in blade template?
ex:
template.blade.php
#yield('css')
#yield('js')
dashboard.blade.php
#section('css')
//some code here
#endsection
group.blade.php
#section('css')
//some code here
#endsection
any help me?
thanks
That's not how the HTTP protocol works. The HTTP protocol is stateless, meaning it does not remember that a user visited the dashboard before they visited group.
The only assurance you have is that when a user visits the dashboard the CSS of the dashboard will be cached so subsequent requests for them will load them from the cache and not from the webserver.
However you must assume that a user could visit group first so all required CSS for group must be included in the group template, even if that means that means you'll be replicating some CSS for each page.
If you really want to load each asset only once then you should use a JavaScript library like jquery mobile to specify different sections that are loaded via AJAX. However the how and why is way too broad a question to cover here.
Why you loading asset with #yield? Just load it on your layouts.
For example app.blade.php which in layouts folder.
app.blade.php
<html>
<head>
<link rel="stylesheets" href="{{asset('css/style.css')}}"/>
<title>title goes here</title>
</head>
<body>
#yield('content')
<script src="{{asset('js/jquery.js')}}"></script>
</body>
</html>
Then load layout on any view for example dashboard
dashboard.blade.php
#extends('layouts.app) //it loads all template data from layouts(app.blade.php)
#section('content')
content for dashboard
#endsection

CKEditor editable content in IFrame

Is it possible to run ckeditor on an IFrame so that can encapsulate a full html page? I have tried various methods but nothing seems to work.
What I am looking for is to have a ckeditor wrapper page say Editor.htm which contains an editable IFrame linked to my real html page say test.htm. Something line:
Editor.htm
<!DOCTYPE html>
<html>
<head>
<script src="http://cdn.ckeditor.com/4.5.10/standard-all/ckeditor.js"></script>
</head>
<body>
<iframe contenteditable="true" src="test.htm" id="editor1" name="editor1"></iframe>
</body>
</html>
You can set ckeditor to use "fullPage" mode, allowing you to edit everything from the opening tag to the closing tag. See the official sample here.
You will still need to get the content into the editor (e.g. the html page you want to edit) and save the result on the server, but this is something specific to your site, language, platform etc.

Is there a way in Total.js to add to #{head} from a view?

I'm using total.js and wanting to add a page-specific CSS link tag to a page's HTML <head> from within a view, rather than coding it into the route's controller.
I've tried to use #(head(css('page.css'))} but that results in a server error. Using #{css('page.css')} prints out the CSS link tag as part of the #{body}. Yet, the #{meta('Page Title')} directive is able to direct its output to the <head> section of the page.
Am I missing something or is it just not possible in this version of total.js?
Try to add #{head('/css/page.css')}.

How not to be confined into content area... full size web app on Joomla

I am currently creating an Intranet ERP application that will integrate an already existing corporate Joomla 3.1 based web site.
The extension i made so far only has one default controller php file and everything is made using a JavaScript UI framework. (i.e. jqWidgets) So i am not using model, views, helpers.
The other php files are there to respond to the client side interface AJAX requests.
So i mainly need Joomla for the user authentication and session control features but i dont want it to confine my extensions output to the content area... i need the entire document surface... no menu, no module columns, no nothing !
Can it be done ?
Two ways
component.php in the template will show only the component's output add &tmpl=component to your urls
Make a custom template that only outputs the component
<html>
<head>
<!-- put what scripts stylesheets you need etc//-->
</head>
<body>
<jdoc:include type="component" />
</body>
</html>

Using webform master page in razor view

I have tried implementing this, but the extension methods are not working when I rewrite them in VB. I am trying to use a corporate master page in my MVC3 application. Right now I have my .Master and my .ascx page. I am confused on how to get it to show in my razor view.
my .ascx page:
<%# control Language="VB" Inherits="System.Web.Mvc.ViewUserControl" %>
<asp:Content ID="Content" ContentPlaceHolderID="ContentArea" runat="server">
<div>
Hello World
</div>
</asp:Content>
When I run it, it gives me this error: Content controls have to be top-level controls in a content page or a nested master page that references a master page.
I use my _ViewStart.vbhtmlto call on the .ascx page.
Trying to hack webforms objects to work with MVC3 is only going to cause you trouble down the road. Redo the file as an MVC3 layout using razor.
Edit: added
Layout File Tutorials:
Making layout pages
Understanding Layout Files
Layouts and Sections

Resources