JQuery – ASP.NET MVC – .load and RenderPartial

asp.net-mvcjquery

For some specific reasons, I need to use the jQuery 'load()' method in order to feed a webpage into a div layer.

Most of these webpages are plain .html files.

However for some, there is some data processing going on – I would like to be able to leverage the ASP.NET MVC model (which the site is built in) – but that's not possible with plain .html pages – so I need to use .aspx/.ascx.

I'm wondering if this is doable, does anyone know if I can load a layer that is retrieved from an .ascx ViewPage in ASP.NET MVC?

Best Solution

The html that you need to generate using the view model can be done in a partial view.

create the partial view (partialview.ascx) and in the controller create the method to get the ActionResult

public ActionResult partialview(){
   //your code
   return partialview(model);
}

now in your html page, use a

$.get("controller/partialview", {any data you want to send}, function(html) {
    $("#divToLoad").html(html);
});