SPORTS STORE

How to display partial view in asp.net mvc 2 using Controller and Action?

<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 sample code from Stephen Sanderson's ASP.NET MVC Framework.

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

I am sure that I am not the first person to implement RenderAction () in this way, so there should be a workaround. Please, help.

+4
source share
2 answers

I found a problem. I always delete the route {controller} / {action} and configure all my routes with lowercase REST, such as URLs. But for Html.RenderAction, you need to have such a common route. I added that the general route to the end of the list of routes, and it worked. - Mahdi February 22 at 14:42

Although I still donโ€™t understand how this exactly works, why route tracing is important and what are the limitations of the route. Perhaps I will do some research later.

+4
source

RenderAction is in MVC2 (docs here ). It looks like you changed your code to use RenderPartial , which is completely different. Change it to use RenderAction and you should be fine. If you do not have it in your version, perhaps you need to upgrade to the latest beta?

+1
source

Source: https://habr.com/ru/post/1303552/


All Articles