asp.net web api - How do I Get with using string parameter? -
i have web api method using ef6 , accepting int parameter called serial. instead of primary key serial want find extserial uri.
here have localhost/api/ah?serial=1
// api/ah/5 [responsetype(typeof(transmital))] public ihttpactionresult gettransmital(int serial) { transmital transmital = db.transmitals.find(serial); if (transmital == null) { return notfound(); } return ok(transmital); }
i need have localhost/api/ah?extserial=abc123
for reason won't take following
// api/ah/5 [responsetype(typeof(transmital))] public ihttpactionresult gettransmital(string extserial) //or [fromuri]string extserial { transmital transmital = db.transmitals.find(extserial); if (transmital == null) { return notfound(); } return ok(transmital); }
you should use ihttpactionresult interface.
try this:
public ihttpactionresult gettransmitalsextserial([fromuri] string extserial) { //return ok(extserial.tostring()); return ok(db.transmitals.where(exs => exs.extserial == extserial)); }
Comments
Post a Comment