How can i render page without loading layout page in mvc? - asp.net-mvc-4

In mvc project,recently I am working on project's performance improvement.I am facing problem for loading layout page.when I am rendering or changing page it should load only content on page,not the layout page.so, I want solution to render my content pages without loading of Layout page.

Set the Layout property of the content pages/views as null on which you don't want the layout page to be loaded.
#{ Layout = null; }

For this you have to use either ajax and partial views or any other javascript UI frameworks like knockoutJS or AngularJS

You would need to use Knockout, Knockout & jQuery can provide you with the postback you are looking for. Here is a link.
http://knockoutjs.com/

Your question is not very clear. Please elaborate it. From my understanding, you wanted a very basic layout for better performance.
This you can achieve by creating a new layout page and remove all the scripts and css files from it. Then use this layout page as your layout for the pages.
Your layout can be very minimal, something like
<!DOCTYPE html>
<html>
<head>
</head>
<body>
#RenderBody()
</body>
</html>

Related

#RenderBody() in MVC4 interfering with twitter bootstrap responsive css

Building a site using ASP.NET MVC 4.5, and using twitter's bootstrap-responsive. I noticed that on re-sizing the page, anything rendered by the _Layout view covers what I have rendered using the #RenderBody() statement. Is there any way to correct this?
I can't say for sure, but your problem probably isn't a consequence of #RenderBody. #RenderBody renders the content of your page that isn't in a section. The issue is probably a consequence of which twitter-bootstrap classes style the layout.
All I can do it point you to http://twitter.github.io/bootstrap/scaffolding.html (until the abbreviated html code is included).

How do I make one View have different content from what's specified in its layout?

Suppose I have many views, each displaying very similar content. Each view uses the same _Layout as defined in _ViewStart.
My _Layout might look like this:
<html>
<!-- some html -->
#ViewBag.SomeViewBagFun
<!-- more html -->
#RenderBody
<!-- more html -->
#SpecialFunction()
</html>
Helper SpecialFunction()
#Linky
#<!-- complex HTML -->
End Helper
Suppose 90% of my pages use the default SpecialFunction() as defined in the layout, but occasionally some views want a different SpecialFunction().
One way to resolve this is to use ViewBag and send each view content that way, but SpecialFunction() contains complex HTML and I want to use razor views.
How do I achieve this?
The best way to do this is to use a Section and when you render it make it NOT required.
See ScottGu's blog for some details: http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx
You can specify the layout in the actual View, as such,
#{
Layout = "/address/to/your/different/layout.cshtml"
}
Look at this question for further info.
You can add a condition to your viewbag and based on the value the layout would execute specialFfunction or someOtherFunction Scott Guthrie gives a great example of this technique in his blog
OP here.
It's been a while since I used ASP.NET MVC & Razor. I forgot about Sections. I feel silly ^^
Solution:
_Layout
<html>
<!-- some html -->
#ViewBag.SomeViewBagFun
<!-- more html -->
#RenderBody
<!-- more html -->
#If IsSectionDefined("SpecialFunction") Then
#RenderSection("SpecialFunction", False)
Else
#SpecialFunction()
End If
</html>
Helper SpecialFunction()
#Linky
#<!-- complex HTML -->
End Helper
Another View
Section SpecialFunction
<p>Very different HTML!</p>
End Section

Grails Resources Plugin resource scope

I am struggling to understand the scope of resources defined with the Grails resources plugin.
I have created a small project (Grails 2.0.4) with a single domain item of Book and generated the associated Controller and Views.
I have then modified the main layout as follows:
<html>
<head>
<g:layoutTitle/>
<r:layoutResources/>
</head>
<body>
<g:layoutBody/>
<r:layoutResources/>
</body>
</html>
When I run the app I get no styling as expected.
I now add the following to the head list.gsp
<head>
<meta name="layout" content="main"/>
<r:require modules="jquery-mobile"/>
</head>
When I go to the list page now I correctly get the jquery-mobile styling as expected but when I go to the create page I also get jquery-mobile styling but was expecting no styling, as this page does not contain the tag.
It seems that the resources selected for one page are being used for all other pages. Is this expected behaviour?
Thanks,
Kim
Use Resources 1.2, it sounds like this might be an old bug.

Inserting Jquery script file

Hy guys!
On my site I noticed that on some pages I don't have a Jquery library included. But on other pages I see it in my head tag:
<head>
...
<script type="text/javascript" src="/assets/fe9bd624/jquery.js"></script>
<script type="text/javascript" src="/assets/fe9bd624/jquery.ba-bbq.js"></script>
...
</head>
In my theme layout/main.php I don't have Jquery files in head tag. So question is: what controls inserting Jquery on my pages, and how to insert it on all pages. Thx.
jQuery would only be inserted automatically if you call the registerCoreScript method. There's nothing built into Yii to force jQuery upon you.
However, it could be that your using a widget or extension somewhere that uses jQuery, which would make it's own call to the registerCoreScript. (CGridView for example)
If you use any widget or component or extension which needs jquery & using function registerCoreScript than jquery will be loaded automatically otherwise YII does not load any JQuery.
In every view that requires jquery you can put this on top:
<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>
You can put it into your layout also if you want to include in all pages in a particular layout.

<BODY> of the views in a "scaffolded" Ruby on Rails 3 web-app

do you know how can i modify the <BODY> tag of the rendered htmls files of my app's views?
I mean, i can manually edit the html, but the <BODY> tag is added automatic in run time...
And i'd like to do something like
<body bgcolor="#0000FF">
Thanks!
You need to edit the application.html.erb in the layouts subfolder of views in your application.
Of course, you'd be much better of doing this in a stylesheet rather than the markup directly :)