0

I'm a few weeks into MVC now, and each day, something new pops up which strikes me as quite odd. So, I try to find answers to the issues I'm facing. None the less, for the current issue, I can't seem to find a descent answer here on stackoverflow, or anywhere on google for that matter...

I'm having an issue passing parameters to my controller using the HTML.RenderAction method. For some reason, the parameter ends up correctly in the RouteData, but the "function parameter" is null. I think it has to do with my routing maps, so I'd like to post them here for some more input.

My routemap (amongst others, but I know my current action is using this root):

routes.MapRoute("Default","{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = "" },
            null,
            new[] { "Web.Controllers" }
        );

My controller action:

public ActionResult GeneralManagementDetail(int? id)
{
        //dostuff
}

The RenderAction call:

<% Html.RenderAction("GeneralManagementDetail", "Person", new { id = 4 }); %>

Where of course the "4" currently is a hardcoded value, and it will become an id of an object from the containing foreach loop I have there.

Now, what this results into, is that the "int id" in the controller is NULL, however when "QuickWatching" the RouteData, it definitely has a keyvalue pair "id,4" in it...

Tim Geerts
  • 311
  • 5
  • 14
  • This works for us, but we're not re-using a token from the URI. Does it work if you change `id` to `detailId` in both the action and the call to `RenderAction`? – Craig Stuntz Feb 03 '10 at 14:12
  • No, initially I thought this was the issue as well, so I used a parameter name that was no where near any of the names used in all of my mappings, and it gave the same result. – Tim Geerts Feb 03 '10 at 14:24
  • Hmm... Well, it works for us, but we're using MVC 2. You might want to try this in isolation in a do-nothing project and see if it changed between MVC 1 and 2. Since this is in Futures, it's not fully tested in MVC 1. – Craig Stuntz Feb 03 '10 at 14:54

2 Answers2

1

Ok, just to clarify, the issue apparently was that the controllers were being cached in the framework provided to us (different dev-team does the framework). So, when we dug into the framework, and made sure that the containers weren't cached anymore, the passing of the parameters worked like a charm. Thanks a lot for the answers, but the issue was within our own company it seems!

Tim Geerts
  • 311
  • 5
  • 14
0

Maybe "id = (int?)null" will do the trick? I mean, what if types are messed up.

queen3
  • 15,333
  • 8
  • 64
  • 119
  • Didn't do the trick either... None the less, I think I'm gonna solve it in an other manner, as in rendering a partialview with the "RenderPartial" option, and just passing on a submodel of the mainmodel. That will work and will still be a viable solution for the website. (And it might actually be more correct structure wise). – Tim Geerts Feb 04 '10 at 09:38