2

I have the following controller, inside an area called "Service":

namespace Web.Areas.Service.Controllers
{
    public class IntervalController : Controller
    {
        //
        // GET: /Service/Interval/

        public JsonResult Monitor(String accountId, int datekey)
        {
            //...
        }
    }

}

The URL

http://localhost/Web/Service/Interval/Monitor?accountid=123&datekey=123

is returning an ASP.net error:

"The parameters dictionary contains a null entry for parameter 'accountId' of non-nullable type 'System.Guid' for method 'System.Web.Mvc.JsonResult Monitor(System.Guid, Int32)'"

How can I set up routing to pass the parameters to the controller properly?

2
  • 1
    You've got accountid in the url parameter and the controller expects accountId. But not sure if that's the problem Commented Sep 29, 2010 at 12:31
  • 2
    Can you post your routes and any other Monitor methods you have overloaded in your controller. It looks like the URL you are requesting is calling the wrong action (since your method parameters take string, int and the action being called takes guid, int). Commented Sep 29, 2010 at 12:33

3 Answers 3

1

It's saying you have a guid, do you potentially have another override, or do you have an action name attribute specified for one of the methods defined as Monitor?

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

Comments

1

Maybe you need to add in Global.asax: (the next lines are in VB but it's almost the same)

routes.MapRoute( _  
        "Monitor", _  
        "{controller}/{action}/{accountId}/{datekey}", _  
        New With {.controller = "Home", .action = "Index", .accountId = UrlParameter.Optional, .datekey = UrlParameter.Optional})

Look the parameters are optional so you can pass string, long, or any data type. I prefer do not write a MapRoute for each action, so try to standard it

routes.MapRoute( _  
        "WhatEver", _  
        "{controller}/{action}/{parameter1}/{parameter2}", _  
        New With {.controller = "Home", .action = "Index", .parameter1 = UrlParameter.Optional, .parameter2 = UrlParameter.Optional})

So you can use it to another action no matter the data type but it matters the numbers of parameters.

Comments

0

I looks like you have another action overload that is being matched instead of the one in your question since your current URL is throwing an error trying to match System.Web.Mvc.JsonResult Monitor(System.Guid, Int32), which obviously isn't the action you want.

public JsonResult Monitor(Guid accountid, int datekey)
{
   //...
}

Without actually seeing your routes it is a little hard to tell exactly what is going wrong. However, one thing that you should change in your URL is to make the accountid be accountId to match the case of the parameter in the Monitor action. That would make your new URL be the following:

http://localhost/Web/Service/Interval/Monitor?accountId=123&datekey=123

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.