# Views in Asp.net core MVC
1. return View()
- asp.net mvc core looks for the view with name equal to 'action name'
public ViewResult Details()
{
return View();
}
In this example it will try to load Details View in folder <Controller>Views\<Action>name
2. View(string viewName) method
- It will try to load view with the name 'viewName'
return View("Test");
- it will look for view 'Test.cshtml'
3. Specifying view file path
- return View("MyViews/Test.cshtml");
4. Relative View File Path
- return View("../Test/Update");
5. View(object model) pass model data
6. View(string viewName, object model) Pass both the view name and model data.
## Passing data to view in ASP.NET Core MVC
1. there are 3 ways to pass data from a controller to a view
- Using ViewData - loosely typed view
- Using ViewBag - loosely typed view
- Using a strongly typed model object. This is also called Strongly typed view.
## Using ViewData to pass Data from a Controller to a View
1. in controller ViewData["PageTitle"] = "Employee Details";
2. Accessing ViewData in a View
- <h3>@ViewData["PageTitle"]</h3>
Tuesday, 22 March 2022
Views in Asp.net core MVC
Subscribe to:
Post Comments (Atom)
Search This Blog
Creating your first "Alexa" Skill
Index What is Alexa What is Alexa Skill? Why is it required when Alexa already equipped with voice assistant? Dev...
About Me
Menu
-
Index What is Alexa What is Alexa Skill? Why is it required when Alexa already equipped with voice assistant? Dev...
-
Adding Azure AD B2C to React Native App Register your app in Azure active directory 1. Go to azure ad b2c, app registratio...
-
# Project file 1. .net Core project file no longer contains file or folder reference - all files and folder present within the root fol...
No comments:
Post a Comment