0

I have a tag cloud that I'm including on nearly all of the views that I have in my site. I realize that I can put it on a master page. The bigger question is, how do I pass it the data from the database? I'd like to avoid having to fetch the data in every single controller and action. Is there an easy way to do this?

Darthg8r
  • 12,377
  • 15
  • 63
  • 100

1 Answers1

4

Use @{ Html.RenderAction("TagCloud", "SomeController"); }.

 public class SomeController : Controller {
    public ActionResult TagCloud() {
        var model = // fetch data for tagcloud
        return View("~/Views/Shared/Tagcloud.ascx", model);
    }
 }

It's quite common to load a view that has it's own view model, f.e. because it's shared among a lot of different pages and scenario's, in it's own action.

Jan Jongboom
  • 26,598
  • 9
  • 83
  • 120