Good day. I wanted to realize one interesting thing, but I can not reach it. I have mvc4. I need to display the number on the Master page (just some number of list items). List - the number of orders. I do not know how to make it so that without addressing the controller so that it can be displayed (with the exception of BaseContorller - the common controller). Maybe you have advice on the output to the global page.

PS Data needs to be output on each page using MasterPage (options with "bring the model out of the controller" - do not fit).

  • And where is this number stored? Why not use the session? - user2997

1 answer 1

I see several solutions.

  1. Static class = ( Say
public static class OrderHelper { static int GetCount() { //// return count ; } } 

2) Create an action.

 public class OrderControler : Controler { public int Count(){ return count; } } 

then on the page where you need to use as

@ Html.Action ("Count", "Order")

3) Define BaseViewPage

 public abstract class BaseViewPage : WebViewPage { public int OrdersCount () { return count; } } public abstract class BaseViewPage<TModel> : WebViewPage<TModel> { public int OrdersCount() { return count; } } 

And in the web.config fix pageBaseType = "NAMESPACE.BaseViewPage"

And then on any page you can call

OrdersCount ()

PS Choose you. I am only confused

using MasterPage

Is it an aspx?