I'm new to coding WEB APIs (using VS 2013) and I have tried to get a stored procedure to return results in JSON. I have found examples using HTML for display, but I can't get it send JSON. I'm working with that example and the error I'm seeing is "The name 'view' does not exist in the current context". I usually work though problems pretty well using the message boards (and I feel I'm close) but I just can't seem to get this to succeed. The data is there from the sproc but I don't know how to return it. This is my first post so forgive me if the answer turns out to be obvious.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TRYiT.Models;
namespace TRYiT.Controllers
{
public class TRYiTController : ApiController
{
TRYiTEntities _db = new TRYiTEntities();
public IEnumerable<InfoModel> Get()
{
var studentercord = _db.Student_sp().ToList();
InfoModel objmodel = new InfoModel();
objmodel.infoData = new List<info>();
foreach (var item in studentercord.ToList())
{
objmodel.infoData.Add(new info { StudentID = item.StudentID,
LastName = item.LastName,
FirstName = item.FirstName,
EnrollmentDate = item.EnrollmentDate,
MiddleName = item.MiddleName });
}
return view(objmodel);
}
}
}
Viewmethod is not a part of web api.objectmodel, or some IEnumerable<InfoModel> like your method signature