Web API return list of custom type (json)

In this Article we will learn Web API how to return list of custom type (Jason).

Start visual studio and select new project from the start page.  Or from the File menu, select New and then Project.

In the Templates pane, select Installed Templates and expand visual C# node and select web. In the list of project Templates, select ASP.NET Web Application and Click OK. And give your Project name Like StudentApp.

1

In the new ASP.NET Project dialog, select Web API and Click Ok

2

We got StudentApp (our Application Name) Application with Installed all need Files

3
Add Model :

Click Model Folder, add Student and ResponseModel Class with in Model Folder

Student Class:

ResponseModel Class:

Actually Student Class we use for Student Property and ResponseModel Class we use for Return Type. we will pass all student within  ResponseModel Class after few minute we will see to use this Class

Add Controller :

Click Controller Folder, right button click, add click, click Controller and Select Web API 2 Controller, click Add and give you’re Controller Name (StudentController).

And run,give url (/api/student) we can see output

outApi

Leave a Reply

Your email address will not be published. Required fields are marked *