First off I’m not sure that’s the proper title for this question but hopefully I’ll do a better job trying to explain what I need to accomplish.
Introduction
What I want to do is load the FAQ information that is relative to the page I’m on. So say I’m on the page http://www.domain.com/items/index, I want to load the FAQ information that describe what can be done on this page and what options are available… etc. Then, the user rolls over a search bar, I want to display (on the side of a page) a short text that describes the search box and how it works (like telling them you could search by keywords or for a specific item or… etc). And it goes like that for the rest of the pages and stuff on those pages.
Brainstorming
Ok so what I have in mind so far, and which I’m not sure of (hence this is why I’m posting the question) is as follows:
- In the database, create two tables: PageFAQ and ElementFAQ where an ElementFAQ is a child of PageFAQ. The reason why I thought about this is so I would load the PageFAQ and all ElementFAQ all together and dump them into the page and hide them.
- At this point, I would only display the summary text of the PageFAQ which tells the user more about the page and some of the available options.
- Now, in order to load the correct ElementFAQ, some steps should be taken on the server and client side:
- Make sure the Id’s/Names of the ElementFAQ’s in the database match those of the hidden divs that were dumped into the page previously (when the PageFAQ relative to the page was loaded)
- When the user rolls over an element (say the search bar), I would use jQuery to search for a div with id faq_searchBar and display its innerHTML inside the FAQ side box.
Problem
All what is mentioned above should theoretically work. But I can’t get my mind around how to map between the “page” I’m currently viewing and the PageFAQ entry in the database. As you know, there aren’t really pages in ASP.NET MVC, there are only routes. So is there some way I could use route data to fetch the needed PageFAQ? Or should I use the query string? Or is there a better way of doing this all together, preferably something that does not use magic strings in the first place.
UPDATE:
Would it be too much overhead loading the PageFAQ and all its ElementFAQ children and dump them into the page as hidden divs? Or would it be a better idea to load them via AJAX when the user rolls over the element?
Your suggestions are most welcome.
The CalculateId could simply associate the current controller and action to the corresponding id in the database or directly add those columns in your database and then query: