开发者

Parameter ok in RouteData but passed as null in controller

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 RenderAct开发者_开发百科ion 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...


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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜