Following is my code snippet which works fine, my query follows the code:
Model:
namespace CVHub.Models
{
[DataContract]
public class Context
{
[DataMember]
public int sessionID { get; set; }
[DataMember]
public string Name { get; set; }
public static List <Context> Contexts= new List<Context>
{
new Context{sessionID=1,Name="Name1"},
new Context {sessionID=2,Name="Name2"},
new Context {sessionID=3,Name="Name3"}
};
}
}
Controller:
namespace CVHub.Controllers
{
public class ContextController : ApiController
{
List<Context> items;
// GET api/values
public IEnumerable<Context> Get()
{
//return Context.Contexts;
return items;
}
}
}
Question: I want to use an external json file (residing in app_data folder) to serve same data instead of doing new Context{sessionID=1,Name="Name1"},
how to use a data I read from json file? I am very new to MVC and webApi, so it will be of great help if the experts can post the entire working code or as much details as possible please.