views:

144

answers:

2

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...

A: 

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

queen3
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
+1  A: 

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