How to add an already built view to a controller with asp.net core 2.0

0

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?

    
asked by anonymous 27.06.2018 / 18:43

1 answer

3

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,Ihave5viewsinsidetheCompanyfolder.

BasedonwhatIsaidabove,youshouldthenhaveaControllercalledCompanyControlleranditmustbeinsideafoldercalledController.

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.

    
27.06.2018 / 19:45