I am using ASP.NET MVC 3, and I have an interesting problem to solve, which I hope for some tips.
I have a page that has multiple divs. The content of each div changes over time, and therefore, I currently have a timer for each start of the div that requests $ .ajax to the server, which returns a PartialViewResult with the updated contents of the div. The partial view is quite complex and refers to other views.
The problem with this approach is that it does not scale very well. Perhaps each user has many of these timers, and with a large number of users, the server constantly gets into. Therefore, I would prefer to make one request to the server, which returns, possibly, several div contents in such a way that it will be:
div1 { some html } div2 { some html }
...
Then on the client, I could put every bit of HTML at the right position on the page.
I thought that what I can do is return the JSON from the server, but my problem is how do I get the HTML? At the moment, the razor compiler will start and turn my partial cshtml files into HTML, but if I return JSON, can I call the razor compiler programmatically?
I found the Razor Engine here: http://razorengine.codeplex.com/ , which seems to do what I want, but is it possible to do this using only vanilla ASP.NET MVC?
Or, given the problem, is there a better way to achieve my goal?
Thanks for any help!
kmp
source share