Return JSON Hardcoded From Controller MVC Core

Code Snippets 4 U
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace CitiesAPI.Controllers
{
    [Route("api/getcities")]
    public class GetAllCities : Controller
    {
        /// <summary>
        /// returns all the cities hardcoded in JSON format
        /// </summary>
        /// <returns></returns>
        public IActionResult GetAllCitiesAction()
        {
            return new JsonResult(new List<object>()
            {
                new {id=1,name="sachin"},
                new {id=2,name="kumar"}

            });
        }
    }
}

Leave a Reply

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

eleven + = twelve