0

I have a controller called AuctionsController with a method

public ActionResult BidsByAuction(int auctionId, int page = 1)

When I navigate to /Auctions/BidsByAuction/38 I get the following error:

The parameters dictionary contains a null entry for parameter 'auctionId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult BidsByAuction(Int32)' in 'Extranet.Controllers.AuctionsController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

What is going wrong here?

3 Answers 3

6

Did you create a cutom route for your method that takes an AuctionID as a parameter? If not, then by default, the parameter is called "id".

If you want auctionid, then you need to make a new route that sets the name to auctionid.

Not entirely sure that will fix your problem, since there may be a problem with the optional parameter as well, but fix this one and see what you get.

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

3 Comments

I didn't create a custom route because there are other methods that don't seem to have a custom route but are using auctionId as a parameter and they work fine.
@Sachin - Are you by any chance passing AuctionId as a form variable? If you have it in your form, then the id will be ignored
@Sachin - Also, your other methods may be adding a querystring parameter called auctionId, rather than using the route parameter of /<id>
0

The "38" is mapped to a the default route last parameter {id}. The second parameter should be optional to not being taking into account if it is not provided in the query string.

Comments

0

Thanks everyone. School boy error. You were all right, I should have used id as the parameter name in the controller method. That is why I got this error.

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.