views:

25

answers:

1

We are adding tooltips to our ASP.NET MVC product, and we are getting the text from our database (technically, from a cached copy of the data). To do so, we created an Html Helper method:

<%=Html.Tooltip(Model.GetTooltipText(Tooltips.ClientPage.StartDateId))%>

The GetTooltipText method is in our BaseViewModel, and simply uses the passed in Id to fetch the tooltip from cache.

Would this be considered a bad design? What other alternatives would we have?

Thanks!

+1  A: 

Its probably a better idea to grab all the Tooltip's in one hit and put them in some sort of strongly-typed collection (perhaps a Dictionary<id,string>), cache all of that in your service layer.

Then you could put this in a ViewModel and pass it through to your strongly-typed view.

In your View you could simply access that strongly-typed collected via the Model based on the unique key?

I.e.

<%: Model.Tooltips[SomeDateId] %>
RPM1984
The cached copy is actually a dictionary, so you're probably right ... we're just adding an extra step (the GetTooltipText) that isn't necessary.
Andrew
Ok - so you're "design" is relating to the helper method, not the cached data. Normally you'd have a service layer to do some sort of data massaging on top of the data layer. But you're not really doing in the service layer (by the sounds of it). If this is the case, why not create Html helper extension methods for all the controls you wish to have tooltips, which actually does that retrieval for you?Then your view would be:<%= Html.DynamicToolTip(StartDateId) =>There are quite a few ways of doing it, the key is to keep the view as clean as possible.
RPM1984
Primarily because we have hundreds of fields with tooltips (this is a very large application). The cached data is accessed by a service layer method, which we had put in the model. Based on your suggestion I'm going to pull the data in the base controller and populate a dictionary in the base view model.
Andrew
Sounds good. Dont forget if you dont want to explicity pass the model data through the view via return View(tooltips), you always use ViewData["ToolTips"], or even TempData["ToolTips"] if you only need the data for a single request. Disadvantages of these two of course is boxing/unboxing.
RPM1984