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



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

i'm new coding web apis (using vs 2013) , have tried stored procedure homecoming results in json. have found examples using html display, can't send json. i'm working illustration , error i'm seeing "the name 'view' not exist in current context". work though problems pretty using message boards (and sense i'm close) can't seem succeed. info there sproc don't know how homecoming it. first post forgive me if reply turns out 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 }); } homecoming view(objmodel); } } }

i hope, looking this.

public ienumerable<info> get() { var studentercord = _db.student_sp().tolist(); ienumerable<info> info = (from item in studentercord select new info { studentid = item.studentid, lastname = item.lastname, firstname = item.firstname, enrollmentdate = item.enrollmentdate, middlename = item.middlename }).tolist(); homecoming data; }

note: have changed homecoming type info, because can't see ienumerable<infomodel> can not returned here, rather makes sense utilize ienumerable<info> . if sense right ,go ahead , create changes.

becaue, can see homecoming type of ienumerable<t> , not have homecoming view . in webapi, need homecoming ienumerable, when execute get request, list of info ( example). mvc, have homecoming view while invoking controller , whereas webapi homecoming type not that.

so assuming, hosted in "http://www.example.com" , has route defined "api/{controller}", need nail "http://www.example.com/api/tryit" list of data.

c# json asp.net-web-api

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -