B
B
Barabasishe2014-04-04 10:01:38
ASP.NET
Barabasishe, 2014-04-04 10:01:38

How to display the menu layout and the main workspace on the main page in an ASP.NET MVC project?

There is a main standard Layout in which I display parts of the top menu _NavigationLayout, the side menu _PanelNewsLayout, the workspace using @RenderBody ().

<!DOCTYPE html>
<html>
   ...
    <body>
        @Html.Partial("_NavigationLayout")
        
        <div class="main">
            @Html.Partial("_PanelNewsLayout")
            
            <div class="content">
                <div class="container">
                    @RenderBody()
                </div>
            </div>
        </div>
        ...
    </body>
</html>

The problem is that the _PanelNewsLayout side menu looks like a tree and must be formed using data from the database. Now I made it simple: in the NewsController controller, data from the database is processed and formed into the desired model, which is passed to the Index view and all this is drawn in the workspace using RenderBody. Now we need to make sure that this whole tree is in the side menu.
Tried to move code from Index view to _PanelNewsLayout but model is required.
Alternatively, you can use TempData or Session to store the model.
But is it good?
Perhaps there is another option with replacing the _PanelNewsLayout layout with a view with a controller?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
barbarOFF, 2014-04-04
@barbarOFF

Don't mix markup with logic. Alternatively, you can load the menu through jQuery - call a separate controller method.
You can pass it through ViewBag - take a closer look at how your ViewBag.Title is passed from pages to _Layout - in the standard ASP.NET MVC template

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question