Understanding MVC Core Concept as Beginner
-
_Layout.cshtml :-
- Contain in Shared Folder. This File is Same Like Master Page in WebForms
-
Controller.cs :-
- Calling Any Function With
IActionResultMethod. - For Example -
_Layout.cshtml Code Snippet ->
<a asp-controller="Home" asp-action="Foo"> Foo Text </a>
HomeController.cs Code Snippet ->public IActionResult Foo() { return View(); }This Defining That We Use Foo Method of HomeController
- Calling Any Function With
-
Model :-
- Add New Model File With Visual Studio ->
Right-click the Models folder > Click Add > Click Class > Name the file ModelName.cs - Same as Prop We Made in WebForms. We Can Use Model Directly in View Page With Help of Razor Page Using @ModelName
- Add New Model File With Visual Studio ->
-
- Top of the Page Add
@model ModelName - For Storing Value in Model We Use
asp-forattribute in Element
For Example :<input type="text" asp-for="FirstName" id="FirstName"> asp-forOnly Works When we addModelinto our View page as per First Point
- Top of the Page Add