2

I have created the following ActionMethod as suggested here:

[Route("[action]")]
public IActionResult Orders([FromRoute] int[] filterby)
{
    ICollection<Order> all;
    if(filterby.Length != 0)
    {
        all = _db.Orders.Where(s => filterby.Contains((int)s.Status)).ToList();
    }
    else
    {
        all = _db.Orders.ToList();
    }

    return View(all);
}

When the request URI is something like:

http://localhost:5000/admin/orders?filterby=0&filterby=1

The filterby parameter is always an array of 0 length. What can't I get it working?

5
  • 1
    Try changing to [FromUri] as suggested by your link. Commented Apr 6, 2016 at 10:17
  • @Zaki, [FromUri] doesn't exist. Commented Apr 6, 2016 at 10:19
  • make sure System.Web.Http is imported msdn.microsoft.com/en-us/library/… Commented Apr 6, 2016 at 10:21
  • @Zaki, There is no System.Web, it's ASP.NET CORE! Commented Apr 6, 2016 at 10:22
  • 1
    @VSG24 If you have enough rep, add the answer as an actual answer, rather than editing your question. That will show other users that the question has been answered, and will be easier to find. Commented Apr 6, 2016 at 10:41

1 Answer 1

3

When using ASP.NET core you have two choices:

  1. (Recommended) Use the new attribute [FromQuery]

  2. Import the package Microsoft.AspNet.Mvc.WebApiCompatShim and use the old [FromUri]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.