Web Api routing issue when using uri parameter and query string

Web Api routing issue when using uri parameter and query string

By : Shoeib
Date : November 20 2020, 09:01 AM
I hope this helps . So I've managed to get it working, the controller needed to be declared with [FromUri] for the id parameter:
code :
public IEnumerable<User> GetUsersInAnOrganisation([FromUri] int id, string email = "", string firstName = "", string surname = "", string orderByColumn = "", string orderBy = "asc", int start = -1, int end = -1)

Share : facebook icon twitter icon
Routing based on query string parameter name

Routing based on query string parameter name

By : Tintin64
Date : March 29 2020, 07:55 AM
Hope this helps What you need is just only one route below because query string is not used as routing parameters:
code :
    name: "Get Products",
    routeTemplate: "api/products",
    defaults: new { controller = "ProductSearchApi" }
GetProductsByName(string name)

GetProductsByType(string type)
Routing based on query string parameter name in servicestack?

Routing based on query string parameter name in servicestack?

By : Idrises
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You can't route by queryString, which is just an attribute used to populate the Request DTO that's handled by the same Service.
But inside the Service you can delegate to a different Services, e.g:
code :
public class Request
    public string Type { get; set; }

public class MyService : Service
    public object Any(Request request)
        if (request.Type == "abc")
           return Any(request.ConvertTo<AbcRequest>());

       return Any(request.ConvertTo<XyzRequest>());

    public object Any(AbcRequest request) { ... }

    public object Any(XyzRequest request) { ... }
return base.ExecuteRequest(request.ConvertTo<AbcRequest>());
using (var service = base.ResolveService<AbcService>())
    return service.Any(request.ConvertTo<AbcRequest>());
asp.net WebApi 2 routing query string json with route parameter

asp.net WebApi 2 routing query string json with route parameter

By : Becca Norman
Date : March 29 2020, 07:55 AM
may help you . '~' in the Route specified on an Action, overrides the Route prefix.
Try removing it. It should work.
code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Routing;

namespace MvcApplication2.Controllers
    public class TestClass
        public string Name { get; set; }
        public int Age { get; set; }

    public class ValuesController : ApiController
        // GET api/values
        public IEnumerable<string> Get()
            return new string[] { "value1", "value2" };

        // GET api/values/5
        public string Get(int id, [FromUri] TestClass objectFromUri)
            return "value";

        // POST api/values
        public void Post([FromBody]string value)

        // PUT api/values/5
        public void Put(int id, [FromBody]string value)

        // DELETE api/values/5
        public void Delete(int id)
How to use routing in angular 2 for query string parameter URL

How to use routing in angular 2 for query string parameter URL

By : Brandon Hargis
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Routing is a useful concept of Angular. First read about it carefully and then try to implement it.
You can read this link: https://coryrylan.com/blog/introduction-to-angular-routing
Query string parameter with WebAPI routing

Query string parameter with WebAPI routing

By : user2723703
Date : March 29 2020, 07:55 AM
With these it helps In a [HttpPatch] type of request, only primitive types are can be used as query strings. And DateTime is not a primitive type.
As your example suggests that you need to pass just the date part to the query string, therefore, you can use string datatype instead and convert it to date inside the action method. Something like this:
code :
public IEnumerable<Order> UpdateOrdersByCustomer(int customerId, string effectiveDate)  //changed datatype of effectiveDate to string
    //converting string to DateTime? type
    DateTime? effDate = string.IsNullOrEmpty(effectiveDate) ? default(DateTime?) : DateTime.Parse(str);

    // do some logic with date obtained above
Related Posts Related Posts :
  • Why do I get a COMException when I try to initialize an Interop.Word.Application?
  • Finding subtotal for column in repeater control
  • dropdownlist item selected throw exception (stack empty)
  • How can I list IIS working processes programmatically?
  • How to access nested object from JSON with Json.NET in C#
  • OpenXml DataValidation set predefined List for columns
  • How to find recurring word groups in text with C#?
  • layout conrols to developp universal apps in windows 8.1 pro
  • Adding strings to a list via for loop xna
  • Using Vertex Arrays with OpenTK
  • Optimizing List<string>
  • C# Local variables
  • How can I merge the results of a group by Linq-to-XML query?
  • How to add Report in ASP.NET Project
  • C# How to display all instances of a loop in a label?
  • C# subscribe a function to System.Action that is subscribed to another System.Action: why does order matter?
  • Is there any negative effect to setting SqlCommand's CommandTimeout to a high value?
  • C# - TreeView Context Menu Out of Place when using keyboard
  • How to read stored procedure output and return it as list
  • How do you maintain changes made by VisualState triggers after setting another VisualState?
  • Should I be unit testing my bootstrapper and if so how?
  • using .SingleOrDefault() inside .Where() will raise the following exception:- System.NotSupportedException was unhandled
  • C# How would I fill a Form1 Parameter in the same seperate class
  • Access gridview row's data from LinkButton inside that row
  • Translating excel function to c# Math.pow not resulting in same values
  • Arranging Ten Inputted Numbers into Ascending and Descending order
  • AsEnumerable and Query Syntax
  • How can I defensively code against randomly referencing "Table 0" and null values?
  • Changing xaml code position based on screen size
  • Castle Windsor resolve ienumerable and name
  • Drawing multiple sprites with a for loop xna 4.0
  • For loop to Populate Textblocks
  • Visual Studio 2015: Create an Empty Project
  • What are .NET classes to replace the old MSXML2.ServerXMLHTTP?
  • Handle leak in .Net threads
  • Excel add-in ribbon click events bubbling
  • validation rule needed for only numbers to be entered
  • Parsing complex XML, no descendent elements exists when selecting a named element
  • Web Api - IEnumerable with complex type as param is null
  • Email address input validation
  • .Net AND operator Regular Expression using strings in a document
  • Windows phone 8.1 POST x-www-form-urlencoded not working
  • Is there any way to make my C# XMLManager work?
  • ASP.NET 5 Console Application (package) - How to create DBContext from connection string?
  • How to use form's function in other class C#
  • WPF Zebra EPL2 Printing issue
  • C# use reflection to capture exception throw
  • Convert strings in DataRow to double
  • Xml-Serialization is not working
  • HTML Agility Pack can't find classes with trailing spaces
  • ComputeHash Calls Inexplicably Differ
  • Creating an array that holds both integers and datetime C#
  • GroupBy multiple columns in Linq with Take()
  • Rename multiple symbols at once? (using Roslyn)
  • Cast lambda in delegate
  • DataContractSerializer using default properties
  • LINQ Query Sum in recordset
  • change left-hand boolean value to be opposite of the right hand value
  • Get node from XmlDocument using xpath
  • Why does a Control's BeginInvoke() target delegate never occur after Dispose() is called on the Control?
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co