So a friend of mine (Yes I do have friends and occasionallyÃ‚Â the ARE real) asked me if there was a way to have a partial control/template have dynamic content using a controller. At first I was like ‘f— no’ but that passed quickly as I realized I was actually answering myself on whether Species should have yet another sequel. As for his question, I gave it some thought and the easiest way I could think it jquery and using it’s ajax method to call a controller and use the response (json for this example) to create the content. Could it be done? You bet your Rolex knock off that you bought in New York from some guy named Loey that looked legit for a guy selling things out of a dumpster.
Turns out the solution is fairly simple. Use jquery to call a controller’s action on the template’s load. Even can pass in whatever you need from the parent container.
Here is the parent page:
Here is the partial template file:
And really that’s it. Very simple. Have the parent page call the partial template method and have the partial template method use whatever value being passed in to send it on to the right controller/action. Once the response is there, update the content. Ã‚Â In this case, result.returnValue that is just a simple string. Ã‚Â Or maybe a puppy. Ã‚Â Could be both.
As a bonus, I will actually post the code. NOVEL IDEA!111
What? Why did I choose purple for the color of Mako markup? Ã‚Â Don’t… just don’t. Ã‚Â You have no right to judge.