March 17, 2018

Simple data localisation with .NET core – Part 3 – Add API Controller to view model data

This tutorial will take you through setting up a project from scratch using iQuarc.DataLocalization. Full source for this data localisarion project can be found on github.

  1. Set up basic .NET core MVC project
  2. Models, database and migrations with code first
  3. API Controller to view model data
  4. Data localisation for models using iQuarc.DataLocalization

We will be using a simple domain of a taking a Course and each Course consists of many Skills. Both Course and Skill data needs to be localised to different languages. We will keep the models super simple and only give them a Title and Name property.

This is the third part. If you already know about models, migrations and controllers, move on to part 4: Add data localisation for models using iQuarc.DataLocalization. If you need to set up a new project you can see part 1: Set up basic .NET core MVC project.

Add API controller to view model data

To reqest data from our models we need a controller. We can create one with the following steps:

1. Right click your Controllers folder and choose Add -> Controller

2. Choose API Controller with actions, using entity framework and click “Ok”¨

3. Select Course as model and your DbContext, name it CoursesApiController and click “Add”

4. Run your application and go to /api/Courses to view your

It will look something like this:

As you see, there are no skills yet, this is due to lazy loading in our generated controllers. We’ll fix that when we do our translations next, in part 4: Add data localisation for models using iQuarc.DataLocalization.