Try removing id from the list of defaults ie just have.
Up vote 0 down vote favorite share g+ share fb share tw.
First off, I'm new to MVC, so please excuse the question if it's basic. I'm using a custom route to create the following URL (http://mysite/subscriber/12345) where 12345 is the subscriber number. I want it to run the ShowAll action in the Subscriber controller.
My route is firing and using Phil's route debugger, when I pass in the above url, the route debugger shows ID as 12345. My controller is accepting an int as subscriberID. When it fires, the controller throws the error "The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.
Int32". Why does the route debugger show a value and the controller doesn't see it? Here's my route (first one is the culprit) routes.
MapRoute( "SubscriberAll", "subscriber/{id}", new { controller = "Subscriber", action = "ShowAll", id=0 }, new { id = @"\d+" } //confirm numeric ); routes. MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter. Optional } // Parameter defaults ); Any idea why I'm getting a null in the ShowAll action?
Here is the action method signature: public ActionResult ShowAll(int id) asp.net asp.net-mvc mvc asp.net-mvc-2 asp.net-mvc-routing link|improve this question edited Jan 12 '11 at 17:01 asked Jan 12 '11 at 16:35Bill Martin1,51521229 75% accept rate.
– Brian Cauthon Jan 12 '11 at 16:55 Yes. Updated the question. – Bill Martin Jan 12 '11 at 17:01 I think the problem is with your constraint.
I'm not a regex ninja though so I can't help you there. – Brian Cauthon Jan 12 '11 at 17:35.
Try removing id from the list of defaults ie just have new { controller = "Subscriber", action = "ShowAll" }.
Still getting the error. I want the ID to be required. – Bill Martin Jan 12 '11 at 16:43 @asp316 updated my answer – Vadim Jan 12 '11 at 17:19.
Found that the controller method signature needs to accept a string as MVC doesn't know what type the passing parameter is and therefore can't cast it to int, but it can enforce it through the constraint. So, the route I ended up with is this: routes. MapRoute( "SubscriberAll", "subscriber/{id}", new {controller = "Subscriber", action = "ShowAll" }, new {id = @"\d+" } //confirm numeric ); and the controller method signature I ended up with is this public ActionResult ShowAll(string id).
Instead of writing "id = 0" in your MapRoute write "id = UrlParameter. Optional" this would definitely work with your action result public ActionResult ShowAll(int id) routes. MapRoute( "SubscriberAll", "subscriber/{id}", new { controller = "Subscriber", action = "ShowAll", id = UrlParameter.
Optional }, new { id = @"\d+" } //confirm numeric ).
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.