model view controller - retrieve data from database into web api -
model view controller - retrieve data from database into web api -
here table:
table name: data
fields:
id category description imagepathi'm building webapi returns imagepath or id.
web api controller:
namespace task.controllers { public class imagescontroller : apicontroller { dataentry db = new dataentry(); public ienumerable<datum> getimages() { var imagepath = m in db.data select m; homecoming imagepath; } public ihttpactionresult getimages(int id) { var imagepath = m in db.data select m; var imagpath = imagepath.where((p) => p.id == id); if (imagepath == null) { homecoming notfound(); } homecoming ok(imagepath); } } }
it's returning fields (id,category, description , imagepath) instead of imagepath only.and select id method it's not working also, wrong??
for imagepath
, seek specifying in linq query so:
public ienumerable<string> getimages() { var imagepath = m in db.data select m.imagepath; homecoming imagepath.tolist(); }
for select id, seek this:
public string getimages(int id) { var imagepath = m in db.data select m; var imagpath = imagepath.where((p) => p.id == id); if (imagpath == null) { homecoming notfound(); } homecoming ok(imagpath.imagepath); }
double check typo such imagpath
, imagepath
too
model-view-controller asp.net-web-api
Comments
Post a Comment