asp.net mvc - View Models (ViewData), UserControls/Partials and Global variables - best practice? -


I'm trying to understand a good way of 'global' members (like current users, themes, etc.) All of my partial As well as in my thoughts.

I do not have to be a logic that can return this data (like BL.CurrentUser) I think it should be a part of the model in my thoughts so I inherited these members from BaseViewData tried. In my controllers, in this way or some other (in a filter or base method in my BaseController), I make an example of an inheriting class and pass it as a visual data. Everything is perfect right up to this point, so my view data is available on the main view with base views. But what about partial?

If I have a simple partial that needs to be displayed in a blog post, then it looks like this:

  <%> @ control language = "C # "AutoAventWireUp =" True "Inheritance =" Viewer Control  "& Gt%;  

And in my opinion, this is a simple code for partially presenting (this is its model. Posts IEnumerable ): < / P>

  & lt;% exotic (posted in P. models. Post) {%> & Lt;% Html.RenderPartial ("Post", p); & Gt%; & Lt;%}% & gt;  

Since the partial model is not based wijdata, I do not have access to those properties. Therefore, I tried to create a postvudadata class, which is inherited from basic visibility. , But after that partially passes to my thoughts, there will be a code to actually create their postview data:

  & lt;% HTML. Render partial ("post", New postiwyde Received {Post p = Current user = model. Current user, ...}); & Gt%;  

or I can use a copy constructor

  & lt;% HTML. Readerparty ("Post", New PostVidade Data (Model) {post = P}); & Gt%;  

I am surprised that before I proceed, there is no other way to implement it.

Any suggestions?

Thank you!

Have you considered putting these things in session and writing a strongly typed cover around the session Can you access this information? Then in any view you can create a new wrapper class with the property of ViewPage (or ViewUserControl) session and you can use it.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -