If you are new for .Net Core MVC template, here you start with creating new page.
AspnetCoreMVCStarter
or AspnetCoreMVCFull
:Create New Controller with .cs
extension in the Controllers/
directory.
Let's create a blank Controller for an example with the file name TestController.cs
and placing the below code in that file.
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using AspnetCoreMvcStarter.Models;
namespace AspnetCoreMvcStarter.Controllers;
public class TestController : Controller
{
public IActionResult TestPage() => View();
}
Create New View with .cshtml
extension in Views/{view_name}/
directory.
Let's create a blank View for an example with filename TestPage.cshtml
in Views/Test/
directory and placing the below code in that file.
The controller TestController.cs
sets view for TestPage.cshtml
TestController.cs
controller has TestPage.cshtml
view.TestController.cs
controller has Test.cshtml
view.
@{
ViewData["Title"] = "TestPage - My Application";
}
<!-- ************** Content ************** -->
<h4 class="py-3 mb-6">Test Page</h4>
Add page link to vertical & horizontal menu. Find _VerticalMenu.cshtml
and _HorizontalMenu.cshtml
files inside Views/Shared/Sections/Menu/
folder.
Option 1: To add menu item as main menu:
<li class='menu-item@(currentPage == "/Test/TestPage" ? " active" : "")'>
<a asp-controller="Test" asp-action="TestPage" class="menu-link">
<i class="menu-icon tf-icons ri-home-smile-line"></i>
<div data-i18n="TestPage">TestPage</div>
</a>
</li>
Option 2: To add menu item as sub menu:
open
class for horizontal menu.
<li class='menu-item@(currentPage.StartsWith("/Test") ? " active open" : "")'>
<a href="javascript:void(0);" class="menu-link menu-toggle">
<i class='menu-icon tf-icons ri-layout-2-line'></i>
<div data-i18n="Test">Test</div>
</a>
<ul class="menu-sub">
<li class='menu-item@(currentPage == "/Test/TestPage" ? " active" : "")'>
<a asp-controller="Test" asp-action="TestPage" class="menu-link">
<div data-i18n="TestPage">TestPage</div>
</a>
</li>
</ul>
</li>
search-vertical.json
and search-horizontal.json
inside wwwroot/json/
folder.{
"name": "TestPage",
"icon": "ri-shopping-cart-2-line",
"url": "Test/TestPage"
},
wwwroot\json\locales\en.cshtml
{all languages json} file to display in multi language."Dashboard": "Instrumententafel",
"Test": "Test",
"TestPage": "Page de test",
Run dotnet watch
command in the project directory to see the changes.