I have a view which calls a partial view using:
Html.RenderPartial
I’d like to call this in isolation using a controller method to stop the whole page having to be refreshed but controller methods returning void seem to destroy the existing view (I get a blank screen).
I have the javascript code to update the HTML document section but I can’t see how to retain the view/get a reference to it in the controller to call the javascript method.
I should add that I’m fairly new to this MVC3 thing.
N.B. to cut a long story short, using JQuery is not an option so we’re limited to Javascript unfortunately.
The basic pattern is to create a PartialView result in the Controller and use that result to update the innerHTML of some container on your page:
HTML
JavaScript
Follow Ajax without jQuery for beginners for creating an Ajax method that doesn’t require JQuery. Essentially:
The above JS could be further refactored to take in a URL and an ID of an element to update.
Controller