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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:59:00+00:00 2026-06-11T21:59:00+00:00

I have an ApiController method that accepts several parameters, like so: // POST api/files

  • 0

I have an ApiController method that accepts several parameters, like so:

    // POST api/files
    public HttpResponseMessage UploadFile
    (
        FileDto fileDto,
        int? existingFileId,
        bool linkFromExistingFile,
        Guid? previousTrackingId
    )
    {
        if (!ModelState.IsValid)
            return Request.CreateResponse(HttpStatusCode.BadRequest);

        ...
    }

When I POST to this I’m putting the FileDto object in the body of the request, and the other parameters on the query string.

I’ve already discovered that I cannot simply omit the nullable parameters – I need to put them on the query string with an empty value. So, my query looks like this when I don’t want to specify a value for the nullable parameters:

http://myserver/api/files?existingFileId=&linkFromExistingFile=true&previousTrackingId=

This does match my controller method, and when the method is executed, the nullable parameters are indeed null (as you’d expect).

However, the call to ModelState.IsValid returns false, and when I examine the erorrs it’s complaining about both the nullable parameters. (The other bits of the model have no errors). The message is:

A value is required but was not present in the request.

Why does it think that a value was required / not present? Surely (a) a value is not required for a nullable, and (b) a value was (sort of) present – in a null-ish sort of a way?

  • 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-11T21:59:01+00:00Added an answer on June 11, 2026 at 9:59 pm

    In addtion to the first answer you should be able to get your code working allow the omitting of the prefix’s on the url if you move all the optional’s to the end of the method declaration and I always set them to NULL for good measure:

    FileDto fileDto,
    bool linkFromExistingFile,
    Guid? previousTrackingId = null,
    int? existingFileId = null
    

    But

    Good point re: an empty URL value with a prefix… is it the same as a NULL… Thinking about strings, Is ?q= an empty string or a null??

    I have attempted to find the exact logic in the framework (and continue to look) that raises these errors but during my experimentation I did find that specifying a binder directly on a URL parameter seems to bypass the logic and allow an empty value after a prefix without a model binding error.

    Like so:

    public class ValuesController : ApiController
    {
        // GET api/values
        public IEnumerable<string> Get(
            [FromUri(BinderType = typeof(TypeConverterModelBinder))] string q = null,
            [FromUri(BinderType = typeof(TypeConverterModelBinder))] int? value = null)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
    
            return new string[] { value.HasValue ? value.Value.ToString() : "", q };
        }     
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that inherits from ApiController. It has a Put-method like this:
Consider an ASP.NET Web API service that redirects public class ThisController : ApiController {
I have ApiController with Get action like this: public IEnumerable<Note> Get(Guid userId, Guid tagId)
I have the following API Controller: public class TestController : ApiController { [HttpPost] [APIAuthorizeAttribute]
I have an ASP.NET Web API application, with an ApiController that features asynchronous methods,
I have created an ApiController with the following method: public User Get(int id) {
Im using the New MVC Web Api I have something like this: public class
Let say I have two methods in MVC 4 Web API controller: public IQueryable<A>
I have the following directory structure: modules/ api/ controllers/ ApiController.php InventoryController.php OtherController.php The init()
In my ApiController class, I have following method to download a file created by

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.