Hi - to my understanding this method is looking to receive a List<>, but I am only wanting it to receive ONE parameter from the list (company) but return the full List<> -
What do I need to do to modify this so that it accepts only one parameter from the list (which as you can see is being used in the where clause)?
public class InvoicePullController : ApiController
{
[HttpGet]
public IEnumerable<InvoiceToDisplay> Get([FromBody] InvoiceToDisplay itd)
{
List<InvoiceToDisplay> result = new List<InvoiceToDisplay>();
using (XamarinEntities entities = new XamarinEntities())
{
result = (from a in entities.Companies
join b in entities.Invoices
on a.compNumber equals b.compNumber
where a.Company1 == itd.company
select new InvoiceToDisplay()
{
company = a.Company1,
invoicenum = b.InvoiceNum,
invoiceamt = b.InvoiceAmt ?? 0
}).ToList();
}
return result;
}
}
[HttpGet]
public IEnumerable<InvoiceToDisplay> Get([FromBody] InvoiceToDisplay itd)
If you'd like to send data to your Web API action via request body, you can try to use [HttpPost] instead of [HttpGet] that only supports passing data via query string.
ManderinViolin12
I am only wanting it to receive ONE parameter from the list (company) but return the full List<>
What do I need to do to modify this so that it accepts only one parameter from the list (which as you can see is being used in the where clause)?
Please go to the definition of your InvoiceToDisplayclass and check the type of companyproperty, and then modify your action to accept a parameter with same type of company property.
For example, if the type of company property in InvoiceToDisplay class is string, you can modify the action as below.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
3 Points
7 Posts
Change Method
Dec 07, 2018 01:47 PM|ManderinViolin12|LINK
Hi - to my understanding this method is looking to receive a List<>, but I am only wanting it to receive ONE parameter from the list (company) but return the full List<> -
What do I need to do to modify this so that it accepts only one parameter from the list (which as you can see is being used in the where clause)?
Contributor
4963 Points
4209 Posts
Re: Change Method
Dec 08, 2018 02:07 PM|DA924|LINK
where a.Company1 == itd.company[0] // would address the first item in the list if itd.compnay is a list.
I really don't understand what you are looking to do.
Maybe, you're talking about the below.
All-Star
40565 Points
6233 Posts
Microsoft
Re: Change Method
Dec 10, 2018 06:52 AM|Fei Han - MSFT|LINK
Hi ManderinViolin12,
If you'd like to send data to your Web API action via request body, you can try to use [HttpPost] instead of [HttpGet] that only supports passing data via query string.
What do I need to do to modify this so that it accepts only one parameter from the list (which as you can see is being used in the where clause)?
Please go to the definition of your
InvoiceToDisplay
class and check the type ofcompany
property, and then modify your action to accept a parameter with same type of company property.For example, if the type of company property in InvoiceToDisplay class is string, you can modify the action as below.
With Regards,
Fei Han