1) How to implement layouts in MVC ?
In \_ViewStart.cshtml file we can mention the Layout name.
Eg:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
In the above example, _Layout.cshtml is the Layout name.
2) Can we use more than one layout in the application ?
Yes.
3) What is RenderSection ?
As per MSDN,
In layout pages, renders the content of a named section
syntax : @RenderSection(string sectionname,bool required) .
The first parameter specifies the name of the section we want to render at that location in the layout template.
The second parameter is optional, and allows us to define whether the section we are rendering is required or not. If a section is “required”, then Razor will throw an error at runtime , if that section is not implemented within a view template.
Eg : @RenderSection("PageScripts",false)
4) What is RenderBody ?
RenderBody statement that defines where the content of a particular View will be injected in the general layout.
Eg: @RenderBody()
5) What is RenderPage ?
As per MSDN,
Renders the content of one page within another page. The page where you will place the content could be layout or normal page.
References :
http://www.codeproject.com/Articles/383145/RenderBody-RenderPage-and-RenderSection-methods-in
6) How do you call Partial Views in MVC ?
Partial Views are HTML templates as regular Views.
An example of a partial view that shows the current date is shown in the following listing:
_CurrentDateView.cshtml
<div class="now">Current date is @DateTime.Now.ToString()</div>
Whenever you need to include this partial view, you can just call it by name as shown in the following example:
@Html.Partial("_CurrentDateView")
In the place of the call, the entire content of the View will be included. You can put this statement in standard views, layout pages, and even in other partial views.
No comments:
Post a Comment