0
I created a view (Razor Page) in an Asp.Net Core 2.0 project. How I build it from scratch and I now need to assign a controller to it. How do I do it?
0
I created a view (Razor Page) in an Asp.Net Core 2.0 project. How I build it from scratch and I now need to assign a controller to it. How do I do it?
3
Your View
must be inside a folder with the same name as the Controller
(but without the Controller. Let’s say your Controller
be called CompanyController
, the name of the folder View
that Controller
will just call Company
) and within a folder called Views
. Below we have an example.
Let’s say your View
is inside a folder called Company
:
In this case, I have 5 views
inside the briefcase Company
.
Based on what I said above, you should then have a Controller
called CompanyController
and this must be inside a folder called Controller
.
Done that, inside your Controller
, you’ll have something like this:
public class CompanyController : Controller
{
public IActionResult Index()
{
return View();
}
}
Where the method Index()
is responsible for calling your View
, by name Index
, inside the briefcase Company
.
0
Just create a class in the controller folder and place the page you want to render:
public class HomeController : Controller
{
public IActionResult Home()
{
return View();
}
}
Browser other questions tagged c# asp.net-mvc asp.net-web-api asp.net-core
You are not signed in. Login or sign up in order to post.