views:

353

answers:

2

Hello,

I'm using RenderAction to include the output of several "components" in my view. But everytime I use RenderAction calls to ActionLink within the nested action produce wrong routes. (Same for RouteLink.) If the action is called directly the correct routes are produced.

So I call the action several times in the index action of my parent view:

<% Html.RenderAction<StateAdminController>(c => c.Index(StateType.Event)); %>  
<% Html.RenderAction<StateAdminController>(c => c.Index(StateType.Booking)); %>  
<% Html.RenderAction<StateAdminController>(c => c.Index(StateType.Communication)); %>  
<% Html.RenderAction<StateAdminController>(c => c.Index(StateType.Payment)); %>

And in the Nested Index-View I try to make an ActionLink to the Edit-method of the StateAdminController:

<%= Html.ActionLink<StateAdminController>(c => c.Edit(state.Id), "Bearbeiten") %>

But the ActionLink points to the Index-Action of my parent view.

Is that an known issue? Can I do something wrong? How ActionLinks should be done, when the action is called from RenderAction?

Thank you in advance.
Regards.

Joachim

A: 

You mentioned routes. It's worth noting that when you use RenderAction, the controller is being called directly (i.e. not from an Url). Hence, it is not going through your routing table.

Robert Harvey
Yes, I meant the routes/links emmited by the nested controller. E.g. by the Html.ActionLink helper method.
Joachim Rosskopf
I'm having a little trouble getting my head around it...Can you give examples of the expected and actual routes/urls?
Robert Harvey
A: 

I would rather design my view model to contain properties for all the variations and then call RenderPartial():

<% Html.RenderPartial("StateAdmin", Model.Event); %>  
<% Html.RenderPartial("StateAdmin", Model.Booking); %>  
<% Html.RenderPartial("StateAdmin", Model.Communication); %>  
<% Html.RenderPartial("StateAdmin", Model.Payment); %>

Or even going fancy with my own extension method which loops through a collection and call RenderPartial() for each one:

<% Html.RenderPartials("StateAdmin", Model.StateTypes); %>

While RenderAction() does the trick, calling and render an action from the view seems a little wrong to me. The view is a result of an action already.

Thomas Eyde