I created a view (Razor Page) in an Asp.Net Core 2.0 project. As I build it from scratch and now I need to assign a controller to it. How do I do this?
I created a view (Razor Page) in an Asp.Net Core 2.0 project. As I build it from scratch and now I need to assign a controller to it. How do I do this?
Your View
must be inside a folder with the same name as Controller
(but without the 'Controller'. Let's say your Controller
is called CompanyController
, the folder name of View
of this Controller
will be called only Company
) and within a folder named Views
. Below is an example.
Let's say your View
is inside a folder called Company
:
Inthiscase,Ihave5views
insidetheCompany
folder.
BasedonwhatIsaidabove,youshouldthenhaveaController
calledCompanyController
anditmustbeinsideafoldercalledController
.
Once you've done this, within your Controller
, you'll get something like this:
public class CompanyController : Controller
{
public IActionResult Index()
{
return View();
}
}
Where the Index()
method is responsible for calling its View
, named Index
, within the Company
folder.