如何使用字符串参数? [英] How do I Get with using string parameter?
本文介绍了如何使用字符串参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有一个使用EF6的web api Get方法,它接受一个名为serial的int参数。而不是主键序列我想从URI中找到extserial。
这是我的获取我在哪里localhost / api / AH?serial = 1
Hi,
I currently have a web api Get method using EF6 and it is accepting an int parameter called serial. Instead of the primary key serial I want to find extserial from the URI.
Here is my Get where I have localhost/api/AH?serial=1
// GET 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);
}
我需要通过 localhost / api / AH获得它?ExtSerial = ABC123
由于某种原因,它不会采取以下
I need to have it get by localhost/api/AH?ExtSerial=ABC123
For some reason it won't take the following
// GET 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);
}
推荐答案
没关系。我明白了。
我使用的是IHttpActionResult接口。
Never mind. I got it.
I used an IHttpActionResult interface instead.
public IHttpActionResult GetTransmitalsExtSerial([FromUri] string ExtSerial)
{
return Ok(db.Transmitals.Where(exs => exs.ExtSerial == ExtSerial));
}
谢谢
Thank you
这篇关于如何使用字符串参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文