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 8240411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:29:03+00:00 2026-06-07T20:29:03+00:00

Trying to set up a new site using MVC RC4 web API in Visual

  • 0

Trying to set up a new site using MVC RC4 web API in Visual Studio 2010, and it just seems to not work: parameter values are never passed to the method.

As far as I can tell I have done everything exactly as described here: http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api

Route configuration:

  routes.Clear();
  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

  routes.MapHttpRoute(
      name: "DefaultApi",
      routeTemplate: "api/{controller}/{action}/{id}",
      defaults: new { 
           id = RouteParameter.Optional 
      }
  );

Below is the regular MVC route, I’ve also tried just removing this entirely to see if there
was some conflict but it made no difference.

  routes.MapRoute(
      name: "Default",
      url: "{controller}/{action}/{id}",
      defaults: new { 
          controller = "Home", 
          action = "Index", 
          id = UrlParameter.Optional 
      }
  );

Test controller:

  public class TestController : ApiController
  {
        [HttpGet]
        public int Double(int value)
        {
            return value * 2;
        }
  }

URL: http://localhost:1505/api/test/double/4

The parameters dictionary contains a null entry for parameter 'value' of 
non-nullable type 'System.Int32' for method 'Int32 Double(Int32)' in
'MyAppName.Controllers.TestController'. An optional parameter must be a
reference type, a nullable type, or be declared as an optional parameter.

Argh. This is about as simple as it gets isn’t it? But nothing seems to result in the parameter being mapped. For the heck of it I also tried

http://localhost:1505/api/test/double?id=4

No difference. If I make the parameter accept null values, e.g.

public int Double(int? value)

it runs, but value is always null.

What am I doing wrong?

  • 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-07T20:29:05+00:00Added an answer on June 7, 2026 at 8:29 pm

    In your route you have {id} but in your action you have value and MVC matches the “things” (route values, query string values etc.) by name.

    So the names should align:

    So change your routing to :

    routes.MapHttpRoute(
          name: "DefaultApi",
          routeTemplate: "api/{controller}/{action}/{value}",
          defaults: new { 
               value= RouteParameter.Optional 
          }
      );
    

    And it will work with the URL: http://localhost:1505/api/test/double/4

    Note: if you leave the value RouteParameter.Optional you need to change type in your action’s signature to int?.

    Or you can change your action method signature:

        [HttpGet]
        public int Double(int id)
        {
            return id * 2;
        }
    

    Or you can leave it as it is just use this URL:

    http://localhost:1505/api/test/double?value=4

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

Sidebar

Related Questions

I'm trying to set up a project for a new web site in Aptana
I'm new to programming and am trying to set up Ruby on Rails using
I just started using Yii, coming from Codeigniter (CI). I'm trying to set up
I am using asp.net mvc, C# and jquery. My site is uses ajax heavily.
I'm currently trying to set up integration/acceptance testing for a new rails 3 application
I'm new to ASP.NET MVC and I'm trying to create a very simple blog
I am trying to add an MSMQ binding for my IIS Web Site, correct
I'm trying to make a simple website using mvc but I'm a little confused
I'm new to MVC but am having trouble trying to find info on how
I am trying to serve an RSS feed from my ASP.net MVC site. Everything

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.