+1  A: 

You can use RenderAction for this to delegate menu rendering to some controller. Another option is to have your controller (or base controller class, or action filter) put the menu object into ViewData, and then your master page will do

<% Html.RenderPartial("MenuRenderView", ViewData["menu"]) %>

where MenuRenderView.aspx partial view consumes the menu object from ViewData["menu"]. What does this object contain depends on your database/code.

queen3
at the beginning of the page I put code, queries confirmed to work well
Ognjen
ViewData.Add("user", user); is correct??
Ognjen
To my knowledge .Add() will fail if there's already "user" key while View["user"] = user will overwrite the value; the choice is yours...
queen3
how call Html.RenderPartial from master page with this Index() action
Ognjen
A: 

The approach that I have taken in the past is to have a base controller class from which all the other controllers inherit. In that base controller class, you can add items into ViewData after the controller is initialized:

protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
    base.Initialize(requestContext);

    ViewData.Add("CommonPageData", CommonPageData);
}

The "CommonPageData" in this case is a property or type CommonPageData (a custom class) whose properties are lazy-loaded. One of the properties is a navigation item collection that is consumed on the master page.

mkedobbs
A: 

User RenderPartial for the Menu, but you're gonna need to pass in the ViewData the datasource for the menu all the time, a solution is to make an abstract BaseController and to put the datasource in the ViewData in the constructor of that base controller
all the controllers will inherit from the base controller

Omu
calling ViewData from controller I dont understand
Ognjen
adding value to the viewdata in the contructor of the base controller, so you can use it in your masterpage
Omu
A: 

I have this block sitting in my Site.Master page:

<script runat="server" type="text/C#">
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        MasterModel = SiteMasterViewData.Get();
    }

    protected SiteMasterViewData MasterModel;
</script>

That Get() method is a static factory method tacked on to the View Data class. All of this is embarrassing but here we are.

rasx