Created
March 27, 2017 02:14
-
-
Save A-Programmer/b9d257b54b6bcea1379083ee61bb44f8 to your computer and use it in GitHub Desktop.
Working with Views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
So its time to working with Views | |
At first create Views folder : mkdir Views | |
Create Home and Shared folder : mkdir Views\Home mkdir Views\Shared | |
Creating files : | |
echo.>Views\_ViewImports.cshtml | |
echo.>Views\_ViewStart.cshtml | |
echo.>Views\Shared\_Layout.cshtml | |
echo.>Views\Home\Index.cshtml | |
Open Startup.cs and add this line to Configure method : | |
app.UseStaticFiles(); | |
In _Views\Shared\_Layout.cshtml write your public html codes (MasterPage) | |
Open _ViewImports.cshtml and _ViewStart.cshtml and add this codes : | |
_ViewImports.cshtml : | |
@using YourProjectName | |
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers | |
_ViewStart.cshtml : | |
@{ | |
Layout = "_Layout"; | |
} | |
**** Yout can set Layout in each view file | |
**** For example you can have _MyLayout.cshtml in Shared folder or in Views folder and in first line of Views\Home\Index.cshtml | |
or any other view set Layout like this : | |
@{ | |
Layout = "_MyLayout"; | |
} | |
Everywhere you want to be a ContentPlaceHolder just use @RenderBody in Layout.cshtml file. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment