In the previous Preview 4 there was a bug about renderaction that couldn't be called with strings but only with typed parameters like:
Html.RenderAction<MessagesController>(x => x.Index(messageParameters)); // This worked
Html.RenderAction("Index", "MessageController", messageParameters); // This gave stackoverflow
In preview 5 seems that RenderAction with string parameters work again with no errors.
I still have a problem as my called controller is correctly called but it doesn't get the parameters and I think this could be a problem in my code more than a new bug.
So:
1) I have an helper methods that render a series of partial views calling the RenderAction method like:
public static void RenderWidgets(this HtmlHelper helper, PageViewData pageData) {
foreach(WidgetViewData module in pageData.Modules) {
helper.RenderAction(module.ModuleMethod, module.ModuleName, module);
}
}
where ModuleMethod could be a string like "Index" for calling the action in the controller and ModuleName is the name of the controller.
The third parameter is the actual module data and I verified with the debugger that at the moment of the call of the method the data is there.
2) My Controller, say MessageController is correcly called as it's method but the parameter is null...
public class MessagesController : Controller
{
public ActionResult Index(WidgetViewData widgetParams)
{
//some controller stuff
return View("~/Views/Widgets/Messages.ascx", widgetParams);
}
}
ronnieb
Member
2 Points
6 Posts
RenderAction in Preview 5
Aug 31, 2008 08:19 PM|LINK
In the previous Preview 4 there was a bug about renderaction that couldn't be called with strings but only with typed parameters like:
Html.RenderAction<MessagesController>(x => x.Index(messageParameters)); // This workedHtml.RenderAction("Index", "MessageController", messageParameters); // This gave stackoverflow
In preview 5 seems that RenderAction with string parameters work again with no errors.
I still have a problem as my called controller is correctly called but it doesn't get the parameters and I think this could be a problem in my code more than a new bug.
So:
1) I have an helper methods that render a series of partial views calling the RenderAction method like:
public static void RenderWidgets(this HtmlHelper helper, PageViewData pageData) {
foreach(WidgetViewData module in pageData.Modules) {
helper.RenderAction(module.ModuleMethod, module.ModuleName, module);
}
}
where ModuleMethod could be a string like "Index" for calling the action in the controller and ModuleName is the name of the controller.
The third parameter is the actual module data and I verified with the debugger that at the moment of the call of the method the data is there.
2) My Controller, say MessageController is correcly called as it's method but the parameter is null...
public class MessagesController : Controller
{
public ActionResult Index(WidgetViewData widgetParams)
{
//some controller stuff
return View("~/Views/Widgets/Messages.ascx", widgetParams);
}
}
Where is the problem and what am I doing wrong?
sgentile
Member
4 Points
6 Posts
Re: RenderAction in Preview 5
Sep 02, 2008 05:25 AM|LINK
Ok I finally found the problem.
I changed the call:
helper.RenderAction(module.ModuleMethod, module.ModuleName, module);
in
helper.RenderAction("Index", module.ModuleName, new {mod = module});
and now the object get passed correctly.