I still piss with MVC and work on a site that uses a lot of “tiles” (you know, the usual “rectangular section with a standard title and some content”) for visual display. Nothing out of the ordinary, just a way to put content in boxes for easy layout and navigation. Currently, "tiles" (my term) are constructed as follows:
<div class="tile"> <div class="tile-header"> <h2>Title</h2> </div> <div class="tile-body"> (arbitrary content) </div> </div>
Note: “custom content” means any content, static or dynamic, so there’s not necessarily something that I can connect to the variable and pass to the helper, I need a little more flexibility.
My question is: what is the best method to use to encapsulate this pattern and facilitate / expressive calling from code? I know about partial representations, but how to transfer a part of a body to a partial representation? (It may just be limited knowledge of MVC)
I tried to create Razor helpers as follows:
@Tile.Begin("Title") (arbitrary content) @Tile.End()
But Razor is choking because I can't include the tile-body closing div. (If I do this, then I have to pass the contents of the body as a string variable, and this is not always possible)
I could see something like this:
@using (Tile.Begin("Title")) { (arbitrary content) }
This seems to me the most elegant, although not as easy to scan as the calls to @ Tile.Begin () and @ Tile.End (). From what I understand, I would need to create a class and implement IDisposable, but when I tried to return a string of raw HTML tags from a helper class, it just wrote the encoded tag syntax to the screen, so I assume I ran into a problem here?
Thanks for any advice. :)