c# - Web API won't return JSON using stored procedure -


Text after "div class =" itemprop = "text">

I have a stored procedure to give results in new APIs and I for web APIs (using VS 2013) Have tried to get JSON I have found examples of using HTML to display, but I can not send it to JSON I am working with that example and I see that the name "view" is not present in the error "in the current context". Although I usually work very well using work boards (and I think I'm close), but I can not get it to succeed. The data is from sproc, but I do not know how to return it. This is my first post so please forgive me if the answer is clear.

  using the 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 & lt; InfoModel & gt; Get () {var studentercord = _db.Student_sp (). ToList (); InfoModel objmodel = new InfoModel (); Objmodel.infoData = New list & lt; Info & gt; (); foreach (var item in studentercord.ToList ()) {objmodel.infoData.Add (update {StudentID = item.StudentID, LastName = item.LastName, FirstName = item.FirstName, EnrollmentDate = item.EnrollmentDate, MiddleName = item.MiddleName }); } Return view (objmodel); }}}  

I hope you are looking for this.

Public IEnumerable & lt; Info & gt; Get () {var studentercord = _db.Student_sp (). ToList (); IEnumerable & LT; Information & gt; . Data = (select update items in studentercord {StudentID = item.StudentID, LastName = item.LastName, FirstName = item.FirstName, EnrollmentDate = item.EnrollmentDate, MiddleName = item.MiddleName}) ToList (); Return data; }

Note: I have changed the return type of information, because I think that can not see IEnumerable of & lt would, InfoModel & Gt; can not be returned from here, but it is IEnumerable & lt; Info & gt; is understandable to use. So if you think this is correct, then go ahead and make changes.

Becaue, as you can see that the return IEnumerable & lt; T & gt; , so you should return view . In webpia, you need to return the ienurmable, so that when you execute obtain , you will get a list of data (for this example). But for MVC , you Controller to implement view does, while return WebApi return type is not

Believing this, it is hosted in "" and the path defined as "api / {controller}", you "http://www.example.com/api / TRYiT " to get the list of data.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -