4
<body> <div id="header"> <div class="title">SPORTS STORE</div> </div> <div id="categories"> <% Html.RenderAction("Menu", "Nav"); %> </div> <div id="content"> <asp:ContentPlaceHolder ID="MainContent" runat="server" /> </div> </body> 

This is a sample code from Steven Sandersons' book "Pro ASP.NET MVC Framework."

This code works with MVC V1 and MvcContrib. What it does, it renders a "Menu()" view of "Nav : Controller". Since ASP.NET MVC V2 includes the Partial() and RenderPartial() functionality, I tried to implement it, but this code doesn't work. I tried to modify it in several ways, but it seems there's no overload function that renders partial views, taking as parameters: 1) Controller name 2) View name

I'm sure I'm not the first person who is implementing RenderAction() in this way, so, there must be a workaround. Please help.

    2 Answers 2

    4

    I found the problem. I always remove {controller}/{action} route and customize all my routes with lowercase REST like URLs. But for Html.RenderAction it is necessary to have such general route. I added that general route to the end of my routes list and it worked. – Mahdi Feb 22 at 14:42

    Although i still don't understand, how EXACTLY this works, why is suck route nessesary, and what are route's constraints. Maybe i will do some research later.

    1
    • It is because RenderAction is much closer to what happens when a controller action is initially mapped via routing. I do agree it would be nice if one could not expose the route but still have RenderAction work. In the meantime, you can expose only that specific route, put [ChildActionOnly] on the actions and you'll not have the default routing in place. As you hinted at, with route constraints, you can lessen the impact the presence of the route may have on your available "routing namespace" (not an issue in most cases but an important consideration with sites that are partially CMS).
      – Cymen
      CommentedMar 26, 2010 at 18:06
    1

    RenderAction is in MVC2 (docs here). It sounds like you've changed your code to use RenderPartial instead which is completely different. Change it back to use RenderAction and you should be ok. If you don't have it in your version, perhaps you need to update to the latest beta?

    4
    • Hi tvanfosson, thanks for your reply. I tried RenderAction earlier, it throws an exception like "no sutable route found in rotes table". It doesnt seem reasonable to add any additional rotes, beacuse i'm not acually using route: Controller and View are invoked Direclty, right? Thanks, Ilya.CommentedMar 9, 2010 at 14:02
    • There is a signature for RenderAction that takes the action and controller, in that order. Your code looks correct -- do you have the latest MVC2 beta? Is it possible that you have a conflict with the MVCContrib lib -- you should remove it from your project, I would think.CommentedMar 9, 2010 at 14:13
    • I have no references to MVCContlib. I'm also sure to have the latest vertion of MVC, which is included in MS VS 2010 RC Ultimate. Additional information will be provided in few hours. Thanks for such a quick replies, tvanfosson.CommentedMar 9, 2010 at 14:43
    • I've checked: <% Html.RenderAction("Menu", "Nav" as string); %> throws an exception No route in the route table matches the supplied values. VS 2010 RC, no mvcContlib used.CommentedMar 9, 2010 at 17:32

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.