Should an ASP.NET masterpage get its data from the view?

前端 未结 3 482
天涯浪人
天涯浪人 2021-01-13 22:01

I\'ve been playing around with ASP.NET MVC with a site containing a Master Page.

I created an MVC user control called ProductThumbnailControl. The user c

相关标签:
3条回答
  • 2021-01-13 22:39

    Looks like my solution is very similar to Microsoft's recommendation with one key exception. I was creatng a ViewData baseclass, and they create a Controller baseclass - which makes a lot more sense.

    However it seems that both ideas could (and should) work in tandem. The MS tutorial below uses a dictionary to store view data, so if you had a strongly typed model you'd also need a baseclass for that.

    Microsoft MVC tutorial

    0 讨论(0)
  • 2021-01-13 22:51

    I would create a ShoppingCart Controller (or separate controllers for each concern) and render usercontrols that use them with RenderAction found in the Futures DLL that you can download from www.codeplex.com/asp.net. It is part of the ASP.NET MVC source code.

    Using a base controller or a 'site model' couples too many things together, creating a testing and maintanence nightmare.

    0 讨论(0)
  • 2021-01-13 22:53

    Our master page takes data from the view. We use strongly typed view names for our views and in the methods for that implementation we also add standard view data that every page needs from our persistent objects (like the application menu structure info, the user info to display on screen and so forth).

    This does have the disadvantage of making our view data for the master page not strongly typed like it is for the Model object, but it works very well for us.

    Your idea is also good. As the idea of the Master page is similar to the idea of inheritance, why not use inheritance to setup your model objects. You could take it a step further and create a model factory that produces your model objects and sets the base class data while it does so.

    0 讨论(0)
提交回复
热议问题