Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:04:33+00:00 2026-06-09T00:04:33+00:00

Can someone help me fill in the blanks with my GET methods for webapi.

  • 0

Can someone help me fill in the blanks with my GET methods for webapi. I want to pass in no parameters and get all results. Pass in an int and get a single result and pass in a named parameter to filter by a typeId / zoneId or both but am struggling to get this to work.

TimeController : ApiController

// Time/  

//Time/1

//Time/typeId=1

//Time/zoneId=1

Time/typeId=1&zoneId=1

The closest I got was with

Global

  RouteTable.Routes.MapHttpRoute(name: "DefaultApi",
           routeTemplate: "api/{controller}/{id}",
           defaults: new { id = System.Web.Http.RouteParameter.Optional}
           );

        RouteTable.Routes.MapHttpRoute(name: "TemplateTimeApi",
           routeTemplate: "api/{controller}/{typeId}/{zoneId}",
           defaults: new {typeId = RouteParameter.Optional, zoneId = RouteParameter.Optional }
           );

Controller

 List<TimeView> Get(int typeId, int? zoneId = null)

 TimeView Get(int id)

but I get a 404 on no parameters.

I can change one of the parameters to a string if the issue is with two integers, however, I would prefer to understand the issue and get it to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:04:34+00:00Added an answer on June 9, 2026 at 12:04 am

    // Time/

    If you take a look your routing table: the first routing is matched, but you don’t have action with no parameter => 404 thrown.

    //Time/1

    Run correct, the first route is matched, in here, it choose the action: TimeView Get(int id) becasue of the name: id on routing match to paramter "id" with this method. Remember, Web API bases heavily on naming convention.

    //Time/typeId=1

    //Time/zoneId=1

    Wrong URL => 404 thrown, I guess you would like to put as query string, should be: Time?typeId=1
    But even wrong because, the first routing is match with parameter "Id", not "typeId", so no action method was found.

    Time/typeId=1&zoneId=1

    Wrong URL too, the same reason with above.

    The correct URL you should have: GET Time/1/1 will match with your second route.

    For more understanding on routing and action:
    http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-and-action-selection

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone help me fill in the blanks with native JavaScript? function getHeading(lat1, lon1,
Can someone help me with creating functions for the following processes? I want to
Can someone help me on how to setup such a result: Want to know
Can someone help me ? i want datagridview display data datagridview1.datasource = _db.Students.Tolist(); and
Can someone please help me fill in the following function in R: #data is
Can someone help fill out this table, or link to a reference, that identifies
Hi All Can someone help me with this problem I have encountered Can I
Can someone help me achieve multiple zend pagination in a view using ajax. I
Can someone help by showing me how to sort a LINQ expression. I have
Can someone help me understand how to write this case statement properly its not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.