Here’s some Javascript I use to create a widget on my site:
var boxText = document.createElement("div");
boxText.class = "infobox-custom";
boxText.style.cssText = "margin-top: -215px; margin-left: -500px; border-radius: 10px; background-color:#438BC0; padding: 5px; height: 400px; width: 600px;";
// Notice this:
boxText.innerHTML = '<p>Some text.</p>';
Pretty simple. I need to set the .innerHTML to something much more complex and just sploshing it into a single line in Javascript doesn’t feel right. It smells – at least to me.
What are my options here?
Can I have a PartialView and return that from my Controller to a jQuery POST request?
What do you recommend?
To be honest it seems like rendering the HTML and sploshing it into the single line is the simplest option, given what you’ve got so far.
If you want to get more serious about having the UI dynamic via JavaScript, you should look into using JavaScript to render a template, and simply serve up data (JSON) from your backend (ASP).
A few templating options: